View gnss.get-location.device.nut
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 { |
View iad.comms.agent.nut
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 |
View UDP_Hub_secure.agent.nut
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> |
View timer.class.nut
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; |
View aysnc.wifican.device.nut
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"); | |
} |
View wifiscan.device.nut
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); | |
} |
View wakereason.example.nut
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; |
View uart.configure.device.nut
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; |
View 1-wire.multiple.device.nut
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."); |
View ALawFixedFrequencyDAC.agent.nut
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
// AGENT CODE | |
const AMPLITUDE = 0x3FFF; | |
const NUMBER_POINTS = 1024; | |
const CLIP_VALUE = 32635; | |
const INCR_X = 0.78531475; | |
local streaming = false; | |
local logTable = [ | |
1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | |
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
NewerOlder