ESP32 recording button presses, and serving webpage that graphs the numbers over time.

Overview

ESP32-IoT-button-graph-test

ESP32 recording button presses, and serving webpage via webSockets in order to graph the responses. The objective was to test the ESP32 webSocket implementation written in microPython.

To implement, upload firmware.bin to ESP32-dev board

copy all *.py files and *.html/js to ESP32 root directory.

connect two buttons, each with pull up resistors (1 KOhm), on pins 18 and 19

Pin 19 keeps track of fastCountPin, i.o.w. high freq pulses.

Pin 18 keeps track of slowCountPin, i.o.w. low freq pulses (acts like a reset button to Pin 19 counter).


Used : WebSocket libs jczic / MicroWebSrv2

Firmware was compiled from scratch in order to accomodate Websocket MicroPython Server files into 4MB flash memory.

Need to find the website that showed me howto compile ESP32 firmware in Linux Mint (Was not an easy task. Lots of trial and error).

boot.py :	

starts the show Need to enable which Wifi script to run --- AccessPoint or local Wifi network Next enable the pulse_detector.py script, which starts the button press detection

pulse_detector.py

initiates PIN properties, init's webSocket server, increases pin counter, prepares JSON packet and transmits client endpoint
also outputs to terminal: access via screen /dev/ttyUSB0 115200 JSON Packet msgJson = {} msgJson['slowCounter'] = slowCounter msgJson['fastCounter'] = fastCounter msgJson['timeDiff'] = str(time_diff_ms) msgJson['timeDiff_units'] = "ms" msgJson['timeT0'] = str(time_t0) msgArr.append(msgJson)

ws_server.py

serves HTML / CSS and javascript files creates / server endpoints for each js,html, css file

ws_index.html

call JS scripts : moment.min.js ( datetime libs ); Chart.min.js ( Chart libs in HTML5 )

The following snippet creates a webSocket instance. The downside, is that the connection disconnects, but doesn't reconnect, if no activity detected.

counter) { console.log(msgJson.timeDiff); } pulses_dataValuesArr.push(msgJson.fastCounter); pulses_datalabelStructure.push(counter); timing_dataValuesArr.push(msgJson.timeDiff); timing_datalabelStructure.push(counter); chartPulses.update(); chartTiming.update(); counter += 1; // }; ws.onclose = function(evt) { console.log("Connection closed."); }; ws.closeConn = () => { ws.close(); } } ">
        function startingWS ()
        {
            ws = new WebSocket("ws://" + window.location.hostname);

            ws.onopen = function(evt) { 
              console.log("Connection open ..."); 
              ws.send("Hello WebSockets!");
            };

            ws.onmessage = function(evt) {
              console.log( "Received Message: " + evt.data);
              msgJson = JSON.parse(evt.data);
              if(msgJson.slowCounter > counter)
              {
                console.log(msgJson.timeDiff);
              }
              pulses_dataValuesArr.push(msgJson.fastCounter);
              pulses_datalabelStructure.push(counter);

              timing_dataValuesArr.push(msgJson.timeDiff);
              timing_datalabelStructure.push(counter);

            chartPulses.update();
            chartTiming.update();

              counter += 1;
              //
            };

            ws.onclose = function(evt) {
              console.log("Connection closed.");
            };

            ws.closeConn = () => {
                ws.close();
            }
        }
You might also like...
LedFx is a network based LED effect controller with support for advanced real-time audio effects
LedFx is a network based LED effect controller with support for advanced real-time audio effects

Welcome to LedFx ✨ -Making music come alive! LedFx website: https://ledfx.app/ What is LedFx? What LedFx offers is the ability to take audio input, an

LT-OCF: Learnable-Time ODE-based Collaborative Filtering, CIKM'21
LT-OCF: Learnable-Time ODE-based Collaborative Filtering, CIKM'21

LT-OCF: Learnable-Time ODE-based Collaborative Filtering Our proposed LT-OCF Our proposed dual co-evolving ODE Setup Python environment for LT-OCF Ins

Uses the Duke Energy Gateway to import near real time energy usage into Home Assistant
Uses the Duke Energy Gateway to import near real time energy usage into Home Assistant

Duke Energy Gateway This is a custom integration for Home Assistant. It pulls near-real-time energy usage from Duke Energy via the Duke Energy Gateway

NYCT-GTFS - Real-time NYC subway data parsing for humans

NYCT-GTFS - Real-time NYC subway data parsing for humans This python library provides a human-friendly, native python interface for dealing with the N

Real-time Coastal Monitoring at the University of Hawaii at Manoa

Coastal Monitoring at the University of Manoa Source code for Beaglebone/RPi-based data loggers, shore internet gateways, and web server. Software dev

Volta: A Virtual Assistant which increases your productivity with time as you use it…
Volta: A Virtual Assistant which increases your productivity with time as you use it…

Volta Official Documentation Overview & Purpose Volta: A Virtual Assistant which increases your productivity with time as you use it… Volta, developed

This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction
This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction

This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction

A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.
A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.

distance sensor cube timer A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost. How to

Hook and simulate global keyboard events on Windows and Linux.

keyboard Take full control of your keyboard with this small Python library. Hook global events, register hotkeys, simulate key presses and much more.

Owner
f-caro
I like Linux, embedded systems programming... My style is break-it-as-you-make-it...
f-caro
ESP32 micropython implementation of Art-Net client

E_uArtnet ESP32 micropython implementation of Art-Net client Instalation Use thonny Open the root folder in thonny and upload the Empire folder like i

null 2 Dec 7, 2021
A ESP32 project template with a web interface built in React

ESP AP Webserver demo.mp4 This is my experiment with "mobile app development" for the ESP32. The project consists of two parts, the ESP32 code and the

null 8 Dec 15, 2022
A simple portable USB MIDI controller based on Raspberry-PI Pico and a 16-button keypad, written in Circuit Python

RPI-Pico-16-BTn-MIDI-Controller-using-CircuitPython A simple portable USB MIDI controller based on Raspberry-PI Pico, written in Circuit Python. Link

Rounak Dutta 3 Dec 4, 2022
Raspberry Pi Power Button - Wake/Power Off/Restart(Double Press)

Control Raspberry pi with physically attached button. Wake, Power Off, and Restart (Double Press) . Python3 script runs as a service with easy installation.

Stas Yakobov 16 Oct 22, 2022
Alternative firmware for ESP8266 with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at

Alternative firmware for ESP8266/ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability

Theo Arends 59 Dec 26, 2022
Python code written to utilize the Korlan usb2can hardware to send and receive data over the can-bus on a 2008 Nissan 350z

nissan_ecu_hacking Python code written to utilize the Korlan usb2can hardware to send and receive data over the can-bus on a 2008 Nissan 350z My goal

Liam Goss 11 Sep 24, 2022
Ingeniamotion is a library that works over ingenialink and aims to simplify the interaction with Ingenia's drives.

Ingeniamotion Ingeniamotion is a library that works over ingenialink and aims to simplify the interaction with Ingenia's drives. Requirements Python 3

Ingenia Motion Control 7 Dec 15, 2022
Simple Microservice to control 433Mhz wireless sockets over HTTP, e.g. on a RaspberryPi

REST-light is a simple microservice to control 433Mhz wireless sockets over HTTP, e.g. on a RaspberryPi. The main usage is an easy integration of 433M

Pascal Höhnel 1 Jan 9, 2022
Iec62056-21-mqtt - Publish DSMR P1 telegrams acquired over IEC62056-21 to MQTT

IEC 62056-21 Publish DSMR P1 telegrams acquired over IEC62056-21 to MQTT. -21 is

Marijn Suijten 1 Jun 5, 2022
It is a program that displays the current temperature of the GPU and CPU in real time and stores the temperature history.

HWLogger It is a program that displays the current temperature of the GPU and CPU in real time and stores the temperature history. Sample Usage Run HW

Xeros 0 Apr 5, 2022