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
uart_response <- "dummy" | |
device.on("resp", function(data) { | |
server.log(data) | |
}); | |
function readUart(cmd) { | |
device.send("req", cmd) | |
// Blocking wait to receive response from the imp |
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
// Log the URLs we need | |
server.log("API Protocol " + http.agenturl() + "?cmd="); | |
function requestHandler(request, response) { | |
try { | |
// check if the user sent led as a query parameter | |
if ("cmd" in request.query) { | |
device.send("req", request.query.cmd) | |
// Blocking wait to receive response from the imp |
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
// Create a data stream at data.sparkfun.com, then enter your keys here: | |
local publicKey = "mKO3DYdxD7UO7dRElmbb" | |
local privateKey = "kzlbm9jJmPUAvpB1ZyEE" | |
local buffer_depth = 300 | |
local total = 0 | |
local nvm_storage = server.load(); | |
if (nvm_storage.len() != 0) | |
{ | |
total = nvm_storage.total |
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(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.mows=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
var websocket = require('websocket-stream') | |
module.exports = function buildWebsocket(url, opts) { | |
opts.protocol = 'mqttv3.1'; | |
opts.type = Uint8Array; | |
return websocket(url, opts); | |
}; |
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(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.mows=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
var websocket = require('websocket-stream') | |
module.exports = function buildWebsocket(url, opts) { | |
opts.protocol = 'mqttv3.1'; | |
opts.type = Uint8Array; | |
return websocket(url, opts); | |
}; |
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
// Create a data stream at data.sparkfun.com, then enter your keys here: | |
local publicKey = "8dX9xNk1w3sOv044oz1m" // These are fake codes, please enter yours | |
local privateKey = "pzbnrbq6XvCzWn556pDE" // These are fake codes, please enter yours | |
function sample(params) { | |
// Extract bits from the data sent by the agent | |
// Combine the 2 bytes of data from Si7020 into a single uint16 | |
// then convert to float. Do this for both temp and humidity | |
local rh_code = (params[0]*256+params[1]).tofloat(); | |
local temp_code = (params[2]*256+params[3]).tofloat(); |
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
// Define the Sensor Address | |
const ADDR = 0x80; | |
// Define register map | |
const HUMIDITY = "\xE5"; | |
const TEMP_FROM_RH = "\xE0"; | |
// Specify the update rate in seconds | |
const update_rate = 60; |
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
// Create a message buffer | |
local msg = "" | |
// A function that is called everytime that the UART receives a byte | |
function serialRx() { | |
//Pull a byte from the UART FIFO | |
local c = hardware.uart1289.read(); | |
// Determine if this byte is a carriage return (triggers to log the line) |
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 readTemp() { | |
// Do your periodic stuff here... | |
// schedule imp to wakeup in .5 seconds and do it again. | |
imp.wakeup(0.5, readTemp); | |
} | |
// start the loop | |
readTemp(); |
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----------------------- | |
function requestHandler(request, response) { | |
try { | |
// Send a read request to the device | |
device.send("getRequest", request); | |
// Blocking wait to receive response from the imp | |
device.on("getResponse", function(data) { | |
response.send(200,data); | |
}); |
NewerOlder