Skip to content

Instantly share code, notes, and snippets.

@erjjones
Last active December 11, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erjjones/4656146 to your computer and use it in GitHub Desktop.
Save erjjones/4656146 to your computer and use it in GitHub Desktop.
Awake Imp post JSON payload
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