Skip to content

Instantly share code, notes, and snippets.

View jenschr's full-sized avatar

Jens Chr Brynildsen jenschr

View GitHub Profile
@jenschr
jenschr / combined.html
Last active April 6, 2024 15:39
Paho MQTT websocket example. I had a hard time finding working examples of using the 1.1.0 version of this lib. Here' a basic setup keeping track of connection and unsent messages.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Konkurranse Nespresso</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js" integrity="sha256-7LkWEzqTdpEfELxcZZlS6wAx5Ff13zZ83lYO2/ujj7g=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
var mqtt = require('mqtt'); //https://www.npmjs.com/package/mqtt
var Topic = '#'; //subscribe to all topics
var Broker_URL = 'mqtt://localhost';
var Database_URL = 'localhost';
var options = {
clientId: 'MyMQTT'+Math.random()*64545353,
port: 1883,
username: 'MyUsername',
password: 'MyPassword',
@jenschr
jenschr / parseNumberToString.cpp
Last active October 30, 2019 10:21
Basic example of how a way parse a number to a char array using Modulo. Works for Arduino, stm32, Teensy and other Microcontrollers.
signed long int myNum = -1701543;
void setup() {
Serial.begin(9600);
delay(2000);
Serial.print(myNum);
char buff[14];
int bufferLength = parseNumberToString( buff, myNum );
Serial.print(":");
Serial.println(buff);
/* HC-05 Serial pass through
The following AT-commands are supported:
AT-command Description
---------- ----------------------------------
AT+ROLE Output the current role (1=master/0=slave)
AT+UART Output UART com settings
AT+UART=115200,0,0 Setup comms to be 115200 baud
AT+ADDR? Check device address
AT+PSWD Check current connection password
/*
LoRa Duplex communication
Sends a message every half second, and polls continually
for new incoming messages. Implements a one-byte addressing scheme,
with 0xFF as the broadcast address.
Uses readString() from Stream class to read payload. The Stream class'
timeout may affect other functuons, like the radio's callback. For an
@jenschr
jenschr / SimpleLoraSender.ino
Created September 10, 2019 11:42
Very simple LoRa client for TTGO 1.0 boards
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
#define SCK 5 // GPIO5 -- SX1278's SCK
#define MISO 19 // GPIO19 -- SX1278's MISO
#define MOSI 27 // GPIO27 -- SX1278's MOSI
#define SS 18 // GPIO18 -- SX1278's CS
@jenschr
jenschr / SimpleLoraReciever.ino
Last active September 10, 2019 11:43
Very simple LoRa 'server' for TTGO 1.0 boards
#include <SPI.h>
#include <LoRa.h>
#define SCK 5 // GPIO5 -- SX1278's SCK
#define MISO 19 // GPIO19 -- SX1278's MISO
#define MOSI 27 // GPIO27 -- SX1278's MOSI
#define SS 18 // GPIO18 -- SX1278's CS
#define RST 14 // GPIO14 -- SX1278's RESET
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
@jenschr
jenschr / SimpleLoraReciever
Created September 10, 2019 11:41
Very simple LoRa server for TTGO 1.0 boards
#include <SPI.h>
#include <LoRa.h>
#define SCK 5 // GPIO5 -- SX1278's SCK
#define MISO 19 // GPIO19 -- SX1278's MISO
#define MOSI 27 // GPIO27 -- SX1278's MOSI
#define SS 18 // GPIO18 -- SX1278's CS
#define RST 14 // GPIO14 -- SX1278's RESET
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
@jenschr
jenschr / TTGO_LORA32_BATT_OLED.ino
Created August 10, 2019 14:03
Battery monitor example for the Banggood version of TTGO LoRa32
const uint8_t blue = 2;
const uint8_t vbatPin = 35;
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
float VBAT; // battery voltage from ESP32 ADC read
SSD1306 display(0x3c, 4, 15);
void setup()
{
Serial.begin(115200);
pinMode(blue, OUTPUT);
@jenschr
jenschr / i2cDetect_example_for_esp32.ino
Created August 10, 2019 14:01
i2cDetect script for the Banggood version of TTGO LoRa32
#include <Wire.h>
#include <i2cdetect.h>
void setup() {
// The Oled screen won't be visible unless we set the RESET line on the screen high
pinMode (16, OUTPUT);
digitalWrite (16, HIGH); // while OLED is running, GPIO16 must go high
// Rather than
Wire.begin(4, 15);