Skip to content

Instantly share code, notes, and snippets.

@hfiennes
hfiennes / agent.nut
Created July 24, 2019 21:10
Tinamous demo with explorer kit
// Class for talking to tinamous; not library quality at this point!
class Tinamous {
_account = null;
_device = null;
_password = null;
_clientid = null;
_mqttclient = null;
_connectcb = null;
@hfiennes
hfiennes / agent.nut
Created February 1, 2019 03:47
Sensirion SPS30 air quality sensor
// Ensure we have a default reading
lastreading <- { "mass_pm1.0":0, "mass_pm2.5":0, "mass_pm4.0":0, "mass_pm10":0 };
// Code to convert particlate density to AQI index
// based on https://gist.github.com/kfury/822bbba2cb0f946abb73baa156722ab1
function Linear(AQIhigh, AQIlow, Conchigh, Conclow, Conc) {
local a=((Conc-Conclow)/(Conchigh-Conclow))*(AQIhigh-AQIlow)+AQIlow;
return math.floor(a+0.5);
}
@hfiennes
hfiennes / agent.nut
Last active November 29, 2020 23:24
imp001 air quality monitoring (with AQI index)
// Ensure we have a default reading
lastreading <- { "pm10":0, "pm25":0, "pm100":0 };
// Code to convert particlate density to AQI index
// based on https://gist.github.com/kfury/822bbba2cb0f946abb73baa156722ab1
function Linear(AQIhigh, AQIlow, Conchigh, Conclow, Conc) {
local a=((Conc-Conclow)/(Conchigh-Conclow))*(AQIhigh-AQIlow)+AQIlow;
return math.floor(a+0.5);
}
@hfiennes
hfiennes / agent.nut
Last active September 10, 2018 01:10
Electric Imp streaming audio player demo (imp001/002/003/004)
// Streaming audio player - agent side
// 20180909 hugo@electricimp.com
// ToDo: lots. Like, parsing the WAV header, transcoding in the agent, etc
// Summary:
// - device asks agent to play a URL
// - agent fetches AGENT_CHUNK sized blocks from the URL using range fetches
// - agent chops these up into DEVICE_CHUNK sized pieces and puts them in
// send_queue. It then refills send_queue every time it gets down to half
@hfiennes
hfiennes / agent.nut
Created June 19, 2017 22:31
Arducam Mini 2MP driver for imp (not fully tested in this form, YMMV)
const css = @"
body {
background: #35a8dd;
color: white;
font-family: ""Helvetica Neue"", ""Helvetica"",""sans"";
}
"
http.onrequest(function(req,res) {
if (req.path == "/camera.jpg") {
@hfiennes
hfiennes / agent.nut
Last active December 27, 2016 12:18
Electric Imp client for FIND
// electric imp client for FIND
// hugo@electricimp.com 20161225
const FIND_GROUP = "group";
const FIND_USERNAME = "username";
const FIND_LOCATION = "someplace";
device.on("location", function(scan) {
server.log(http.jsonencode(scan));