Skip to content

Instantly share code, notes, and snippets.

@LosantGists
LosantGists / arduino-modbus-rtu-mqtt.ino
Created February 28, 2020 18:15
Example sketch that reads values from Modbus RTU and reports them using MQTT
#include <ArduinoModbus.h>
#include <WiFiNINA.h>
#include <MQTT.h>
// WiFi credentials.
const char ssid[] = "wifi-name";
const char pass[] = "wifi-password";
// MQTT credentials.
const char* MQTT_CLIENT_ID = "mqtt-client-id";
@LosantGists
LosantGists / arduino-modbus-rtu.ino
Created February 27, 2020 21:37
Example sketch that reads Modbus RTU data with an Arduino
#include <ArduinoModbus.h>
// How often (in milliseconds) the sensors will be read.
const unsigned long REPORT_INTERVAL = 1000;
void setup() {
Serial.begin(9600);
while(!Serial);
if (!ModbusRTUClient.begin(9600)) {
@LosantGists
LosantGists / sse-example.hbs
Created January 6, 2020 20:59
Losant Streaming Endpoint Example
<html>
<head>
<script>
// Connect to one of your Experience Endpoints.
let evtSource = new EventSource('/api/stream/devices/MY-DEVICE-ID');
//Losant sends events using the mqttMessage subject.
evtSource.addEventListener('mqttMessage', function(e) {
// Very useful during development to see the data format.
{{! Only show the upload form if the user is an admin and a member of the Kanarra Technologies group }}
{{#eq experience.user.experienceGroups.[0].name 'Kanarra Technologies'}}
{{#eq experience.user.userTags.role 'admin'}}
<form action="/maintenance-intervals" method="POST" enctype="multipart/form-data">
<div style="font-size: 16px; text-align:center;margin-bottom:15px;">
Upload new maintenance intervals
</div>
<div>
<div style="text-align:center;">
<input type="file" name="maintenanceIntervals" id="maintenanceIntervals" accept=".csv">
@LosantGists
LosantGists / writing-guide.ipynb
Created April 24, 2019 18:19
Losant Notebook Writing Guide
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@LosantGists
LosantGists / losant-example-vega-lite-configuration.json
Last active October 4, 2018 13:31
Example Losant Vega-Lite Configuration
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"width": {{block.width}},
"height": {{block.height}},
"autosize": {
"type": "fit",
"contains": "padding"
},
"config": {
"axis": {
@LosantGists
LosantGists / esp32-arduino-losant.ino
Created July 13, 2018 13:22
Connecting the ESP32 to the Internet with Arduino and Losant
/**
Copyright (c) 2016 Losant IoT. All rights reserved.
https://www.losant.com
*/
#include <WiFiClientSecure.h>
#include <Losant.h>
// WiFi credentials.
const char* WIFI_SSID = "WIFI_SSID";
@LosantGists
LosantGists / main.py
Created June 4, 2018 16:43
Reading TMP36 temperature data and reporting to Sigfox using Pycom LoPy4
import machine
from network import Sigfox
import socket
import struct
import time
# init Sigfox for RCZ2 (USA, Mexico, Brazil)
# other zones:
# RCZ1: Europe, Oman, South Africa
# RCZ2: USA, Mexico, Brazil
// Import libraries
#require "JSONEncoder.class.nut:2.0.0"
// Log the URLs we need
server.log("Turn LED On: " + http.agenturl() + "?led=1");
server.log("Turn LED Off: " + http.agenturl() + "?led=0");
function sendSensorDataToLosant(data) {
local losantWebhookURL = "LOSANT_WEBHOOK_URL"
#require "HTS221.device.lib.nut:2.0.1"
#require "LPS22HB.class.nut:1.0.0"
#require "WS2812.class.nut:3.0.0"
// Define constants
const SLEEP_TIME = 15;
// Declare Global Variables
tempSensor <- null;