Skip to content

Instantly share code, notes, and snippets.

Avatar

Jens Chr Brynildsen jenschr

View GitHub Profile
View ArduinoStringSep.ino
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
@jenschr
jenschr / index.html
Created Sep 27, 2022
TEK303 Mqtt example HTML
View index.html
<!doctype html>
<html lang="en" data-theme="dark"/>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
<script src="./secret.js" type="text/javascript"></script>
<script src="./mqtt.js" type="text/javascript"></script>
<title>MQTT Demo</title>
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
</head>
@jenschr
jenschr / mqtt.js
Created Sep 27, 2022
TEK303 Mqtt client example
View mqtt.js
const myTopic = "users/jensa/led";
const myServer = "mqtt.toytronics.com";
const client = new Paho.MQTT.Client(myServer,8883, "myClientId" + new Date().getTime());
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
console.log("Start connection!");
var connectOptions = {
View gist:c0d2d5df453742a9af9ee97484cc0877
int sensorPin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
View HK_Feather.ino
#include <Arduino.h>
#include <Wire.h>
#include <i2cdetect.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_DotStar.h>
#include "Adafruit_SHT31.h"
#include "Adafruit_LTR329_LTR303.h"
// There is only one pixel on the board
@jenschr
jenschr / dweetio.ino
Last active Sep 12, 2022
Basic code for setting a Dweet with a GET request on an ESP32
View dweetio.ino
#include <WiFi.h>
/*
* Basic code for setting a Dweet with a GET request on an ESP32
*
* Original by Liz Miller (www.learnrobotics.org)
* Updated for ESP32 by https://gist.github.com/jenschr
*/
// WiFi parameters
const char* ssid = "your-ssid"; // Replace with your ssid
View AWS Camera test
#include "esp_http_client.h"
#include "esp_camera.h"
#include <WiFi.h>
#include "Arduino.h"
#include "Base64.h"
#include "mbedtls/base64.h"
#include <NTPClient.h>
#include <WiFiUdp.h>
View Subscriber.js
import React from 'react';
import { useSubscription } from 'mqtt-react-hooks';
export default function Subscriber() {
/* Message structure:
* topic: string
* message: string
*/
const { message } = useSubscription([
View Status.js
import React from 'react';
import { useMqttState } from 'mqtt-react-hooks';
export default function Status() {
/*
* Status list
* - Offline
* - Connected
* - Reconnecting
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
body { margin: 0; padding-bottom: 3rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
#form { background: rgba(0, 0, 0, 0.15); padding: 0.25rem; position: fixed; bottom: 0; left: 0; right: 0; display: flex; height: 3rem; box-sizing: border-box; backdrop-filter: blur(10px); }
#input { border: none; padding: 0 1rem; flex-grow: 1; border-radius: 2rem; margin: 0.25rem; }
#input:focus { outline: none; }