Skip to content

Instantly share code, notes, and snippets.

View jenschr's full-sized avatar

Jens Chr Brynildsen jenschr

View GitHub Profile
#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>
import React from 'react';
import { useSubscription } from 'mqtt-react-hooks';
export default function Subscriber() {
/* Message structure:
* topic: string
* message: string
*/
const { message } = useSubscription([
import React from 'react';
import { useMqttState } from 'mqtt-react-hooks';
export default function Status() {
/*
* Status list
* - Offline
* - Connected
* - Reconnecting
<!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; }
@jenschr
jenschr / index.js
Created November 2, 2021 13:39
Chat example
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
@jenschr
jenschr / App.js
Created November 2, 2021 11:52
Simple example showing how to add MQTT to your React app
import logo from './logo.svg';
import './App.css';
import { Connector } from 'mqtt-react-hooks';
import Status from './Status';
const mqttOptions = {
username: 'username',
password: 'password', // Passwords are buffers
}
// mqtt-socketio-bridge
//
// (c) Copyright 2018 MCQN Ltd
//
var mqtt = require('mqtt')
var express = require('express')
var app = express()
var http = require('http').Server(app)
var io = require('socket.io')(http)
@jenschr
jenschr / RS485_simple.ino
Last active October 26, 2021 14:17
RS485 simple
#include <SoftwareSerial.h>
const byte receivePin = 8; // green cable (RO)
const byte transmitPin = 9; // orange cable (DI)
const byte receiveEnablePin = 2; // blue cable (RE)
const byte RECEIVER_ENABLED = 0;
const byte RECEIVER_DISABLED = 1;
const byte LED_PIN = 13;
int lastVal = 0;
long lastKnock = 0;
void setup() {
Serial.begin( 9600 );
}
void loop() {
int readVal = analogRead( A2 );
if( readVal > lastVal+5 ){
// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, using a ULN2003 interface board to drive the stepper.
// The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by
// a factor of 68. One bipolar winding is on motor pins 1 & 3 and
// the other on motor pins 2 & 4. The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////
//declare variables for the motor pins
int motorPin1 = 8; // Arduino pin 8 -> IN1