local SSID = "xxxxxxxxxxxxxxx" local SSID_PASSWORD = "xxxxxxxxxxxxxxx" local BUTTON_PIN = 1 -- GPIO5 local RASPBERRY_PI_URL = "http://192.168.1.80:8000/esp8266_trigger" function wait_for_wifi_conn ( ) tmr.alarm (1, 1000, 1, function ( ) if wifi.sta.getip ( ) == nil then print ("Waiting for Wifi connection") else tmr.stop (1) print ("ESP8266 mode is: " .. wifi.getmode ( )) print ("The module MAC address is: " .. wifi.ap.getmac ( )) print ("Config done, IP is " .. wifi.sta.getip ( )) end end) end function transmit_msg() end -- Configure the ESP as a station (client) wifi.setmode (wifi.STATION) wifi.sta.config (SSID, SSID_PASSWORD) wifi.sta.autoconnect (1) -- Hang out until we get a wifi connection before the httpd server is started. wait_for_wifi_conn ( ) do gpio.mode(BUTTON_PIN, gpio.INT, gpio.PULLUP) local function pin1cb(level, pulse) if level == 0 then -- send http request to Raspberry Pi local post_data = '{"ip": "'..wifi.sta.getip()..'"}' http.post(RASPBERRY_PI_URL, 'Content-Type: application/json\r\n', post_data, function(code, data) if (code < 0) then print("HTTP request failed") else print(code, data) end end) -- sleep 1 sec --node.dsleep(1 * 1000000) end end gpio.trig(BUTTON_PIN, "both", pin1cb) end