Last active
December 11, 2015 20:38
-
-
Save erjjones/4656146 to your computer and use it in GitHub Desktop.
Awake Imp post JSON payload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDateTime(){ | |
local d = date(); | |
local datestring = format("%04d-%02d-%02dT%02d:%02d:%02d", d.year, d.month+1, d.day, d.hour, d.min, d.sec); //ISO 8601 | |
return datestring; | |
} | |
class RespInput extends InputPort | |
{ | |
name = "response"; | |
type = "string"; | |
function set(serverresponse) | |
{ | |
server.show(serverresponse); | |
} | |
} | |
local input = RespInput("response", "string"); | |
local output = OutputPort("request", "string"); | |
function awake() | |
{ | |
local signal = format("%d", imp.rssi()) //dBm | |
local voltage = hardware.voltage() | |
local mac = imp.getmacaddress() | |
local bssid = imp.getbssid() | |
local id = hardware.getimpeeid() | |
local time = getDateTime() | |
local response = "{\"impeeBssid\": \"" + bssid + "\",\"impeeId\": \"" + id + "\",\"impeeMac\": \"" + mac + "\",\"impeeSignal\": \"" + signal + "\",\"impeeTime\": \"" + time + "\",\"impeeVoltage\": \"" + voltage + "\"}" | |
server.log(response); | |
server.show(time); | |
output.set(response); | |
imp.wakeup(imp.configparams.period, awake); | |
} | |
imp.configure("System Ping", [input], [output], {period = 30}); | |
imp.wakeup(imp.configparams.period, awake); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment