Skip to content

Instantly share code, notes, and snippets.

// include a couple native Node.js modules
const https = require('https');
const url = require('url');
////// ENTER YOUR LOSANT WEBHOOK URL HERE! //////
const webhookUrl = 'https://triggers.losant.com/webhooks/XXXXXXXX';
const parsedUrl = url.parse(webhookUrl);
exports.handler = function(event, context) {
{
"globals": [
{
"key": "toEmailAddress",
"type": "string"
},
{
"key": "fromEmailAddress",
"type": "string"
},
@LosantGists
LosantGists / example-two-man-switch-workflow.flow
Last active June 15, 2016 16:46
A workflow for receiving state from and sending commands to Losant's Python-powered, Internet-connected two-man switches.
{
"globals":[
{
"key":"phone",
"type":"string"
},
{
"key":"slackUrl",
"type":"string"
}
@LosantGists
LosantGists / sketch.ino
Created June 22, 2016 20:16
Connect LCD Display to ESP8266 NodeMCU
#include <LiquidCrystal_I2C.h>
// Construct an LCD object and pass it the
// I2C address, width (in characters) and
// height (in characters). Depending on the
// Actual device, the IC2 address may change.
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup() {
@LosantGists
LosantGists / bridge.conf
Last active June 23, 2016 21:39
mosquitto-bridge-to-losant.conf
# For debugging
log_type all
# Bridge to Losant
connection bridge-to-losant
address broker.losant.com:8883
bridge_cafile /path/to/losant/LosantRootCA.crt
cleansession true
try_private false
bridge_attempt_unsubscribe false
@LosantGists
LosantGists / node-red-sensortag.js
Last active April 4, 2021 17:31
Node-RED function node to combine SensorTag messages into single payload.
// This function node combines all of the async values
// reported by the sensor tag node into a single
// payload. The flow will only continue when all values
// have been received.
var payload = context.get('payload') || { data: {} };
// Number of total attributes to report.
// When we collect all attributes from the
// sensor tag, the flow will continue.
@LosantGists
LosantGists / pubnub-block-losant-rest.js
Created September 13, 2016 21:16
PubNub to Losant Integration Example
/*
Insert this code in your "Losant REST" PubNub Event Handler.
Make sure the channel name is "losant_rest"
*/
export default (request) => {
// we need this module to make our requests to the Losant API
const xhr = require('xhr');
// put all connection credentials here
@LosantGists
LosantGists / TempLogger.mcScript
Last active September 15, 2016 17:38
GETTING STARTED WITH MC-THINGS AND LOSANT
Class TempLogger
// Device ID of Peripheral in Losant
Const LosantDeivceId As String = "57d85157f3894e01006c6afa"
// MQTT topic in Losant
Const LosantTopic As String = "losant/" + LosantDeivceId + "/state"
Shared Event CheckTemp() RaiseEvent Every 30 Seconds
Dim temp As Float = TempSensor.GetTemp() // Get Temp from sensor
Dim tempstring As String = temp.ToString()
Class test
Shared Event RedLed() RaiseEvent Every 500 milliSeconds
LedRed = Not LedRed
End Event
End Class
@LosantGists
LosantGists / night-light.js
Created October 25, 2016 17:49
A night light in Javascript
var interval = 1000
var isLedOn = false
var lightThreshold = 0.7
// Initilize the LED to be off
digitalWrite(D5, false)
setInterval(function() {
console.log("Light Level: " + analogRead())