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
local netData = imp.net.info(); | |
if ("active" in netData) { | |
local type = netData.interface[netData.active].type; | |
// We have an active network connection - what type is it? | |
if (type == "cell") { | |
// The imp is on a cellular connection | |
local imei = netData.interface[netData.active].imei; | |
server.log("The imp has IMEI " + imei + " and is connected via cellular"); | |
} else { |
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
// FUNCTIONS | |
function onewireReset() { | |
// Configure UART for 1-Wire RESET timing | |
ow.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS); | |
ow.write(0xF0); | |
ow.flush(); | |
local read = ow.read(); | |
if (read == -1) { | |
// No UART data at all | |
server.log("No circuit connected to UART."); |
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
// Hold a reference to the GNSS Session object | |
gnssSession <- null; | |
// Store device location | |
location <- { "lat": 0, "lon": 0 }; | |
function isGnssEnabled() { | |
// Is GNSS ready to use? | |
if (gnssSession == null) return false; | |
try { |
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
/* | |
* Load the libraries that we need: | |
* Rocky to serve the API, | |
* MessageManager to handle the agent-device interaction | |
*/ | |
#require "Rocky.agent.lib.nut:3.0.0" | |
#require "MessageManager.lib.nut:2.4.0" | |
/* | |
* Instantiate instances of Rocky and MessageManager |
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
// ********** Imports ********** | |
#require "Rocky.class.nut:2.0.2" | |
// ********** Web UI ********** | |
const HTML_STRING = @"<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<meta charset='UTF-8'> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0'> | |
<title>UDP Demo</title> |
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
class Timer { | |
static version = "1.0.0"; | |
/* | |
* Private Properties | |
*/ | |
_repeat = true; | |
_period = 0; | |
_timer = null; |
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
// Scan for local WLANs using imp.scanwifinetworks() asynchronously | |
try { | |
imp.scanwifinetworks(function(networks) { | |
if (networks.len() > 0) { | |
foreach (index, network in networks) { | |
server.log(format("%d. %s on channel %d", (index + 1), (network.ssid.len() > 0 ? network.ssid : "<Hidden>"), network.channel)); | |
} | |
} else { | |
server.log("No nearby WiFi networks found"); | |
} |
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
// Use imp.scanwifinetworks() in synchronous mode | |
local wlans = imp.scanwifinetworks(); | |
foreach (wlan in wlans) { | |
local wlanData = format("WLAN '%s' is operating on channel %u (current RSSI: %i) ", wlan.ssid, wlan.channel, wlan.rssi); | |
wlanData = wlanData + "and is " + (wlan.open ? "open" : "closed"); | |
server.log(wlanData); | |
} |
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 logWokenReason() { | |
local s = "Device restarted. Reason: "; | |
local c = hardware.wakereason(); | |
switch (c) { | |
case WAKEREASON_POWER_ON: // 0 | |
s += "Cold boot"; | |
break; | |
case WAKEREASON_TIMER: // 1 | |
s += "Timer woke the imp"; | |
break; |
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
local serial = null; | |
// Set 'serial' according to imp type | |
switch (imp.info().type) { | |
case "imp001": | |
case "imp002": | |
serial = hardware.uart57; | |
break; | |
case "imp003": | |
serial = hardware.uartFG; |
NewerOlder