This file contains hidden or 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 startTime(time) | |
| { | |
| // Send the device a 'pong' message immediately | |
| device.send("pong", time); | |
| } | |
| // When we get a 'ping' message from the device, call start_time() | |
| device.on("ping", startTime); |
This file contains hidden or 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
| connectedString <- "disconnected"; | |
| if (device.isconnected()) | |
| { | |
| connectedString = "connected"; | |
| } | |
| server.log("The device is " + connectedString); |
This file contains hidden or 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
| device.onconnect(function() {server.log("Device connected to agent");}); | |
| device.ondisconnect(function() {server.log("Device disconnected from agent");}); |
This file contains hidden or 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
| server.log("Impee's unique id: " + hardware.getimpeeid()); |
This file contains hidden or 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
| pulseStart <- 0; | |
| function state_change() | |
| { | |
| if (hardware.pin1.read()) | |
| { | |
| pulseStart = hardware.micros(); | |
| } | |
| else | |
| { |
This file contains hidden or 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 getPin9Voltage() | |
| { | |
| // Returns value in volts, between 0.0 and 3.3 | |
| local voltage = hardware.voltage(); | |
| local reading = hardware.pin9.read(); | |
| return (reading / 65535.0) * voltage; | |
| } | |
| function sample() |
This file contains hidden or 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 logDeviceOnline() | |
| { | |
| local reasonString = "Unknown" | |
| switch(hardware.wakereason()) | |
| { | |
| case WAKEREASON_POWER_ON: | |
| reasonString = "The power was turned on" | |
| break | |
| case WAKEREASON_SW_RESET: |
This file contains hidden or 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
| server.log(http.agenturl()); // output the agent url to the log console. |
This file contains hidden or 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
| // logs a secret message that we've base64 encoded | |
| server.log(http.base64decode("SW1wdGFzdGljLCBtYXRlIQ==")); |
This file contains hidden or 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 getBasicAuthHeader(user, password) { | |
| local headers = { | |
| "Authorization" : "Basic " + http.base64encode(user + ":" + password) | |
| }; | |
| return headers; | |
| } |
OlderNewer