IoT - Collabs - ESP Firmware with Guru

From The TinkerNet Wiki
Jump to navigation Jump to search

Modular Firmware

Baseline

This is the basis for pretty much ANY ESP-based firmware project. It'll get your device online.

main.cpp

 1 #include "TopSecret.h"
 2 #include "functions.h"
 3 
 4 void setup()
 5 {
 6   Serial.begin(115200);
 7   delay(50); // Delay to let the ESP get booted before sending out serial data
 8   Serial.printf("\n+---------------------------------------+\n");
 9   Serial.printf("|             ESP Baseline              |\n");
10   Serial.printf("+---------------------------------------+\n");
11 
12   setup_wifi();
13 
14   // Turn off the On-board LED (notice that it's inverted on most ESP boards)
15   pinMode(LED_BUILTIN, OUTPUT);
16   digitalWrite(LED_BUILTIN, HIGH);
17 }
18 
19 void loop()
20 {
21   // put your main code here, to run repeatedly:
22 }

The parts

Work Environment (Platformio/VSC setup)

Declarations and Defines

Individual Functions

MQTT

This is intended to be added to the baseline.

You'll need to add:

lib_deps =
       PubSubClient

to your platformio.ini file.

main.cpp

Add:

setup_mqtt();

to setup() after the setup_wifi(); call.

Put:

DOtheBloodyMQTT();

inside loop()

The rest of the parts

Declarations and Defines

Individual Functions

OTA

Gurus source code...

Source code

Ffffffuuuuuuuu......

Configuration HotSpot

Source code

Wiegand RFID keypad

Source code

NeoPixels

Extreme WIP

This is intended to be added to the baseline.

You'll need to add:

lib_deps =
       Adafruit NeoPixel

to your platformio.ini file.

and put

#include <Adafruit_NeoPixel.h>

in your source

Declarations and Defines

Individual Functions

Web Serving

Source code

TFT Display

Source code

OLED Display

Source code

(upcoming)

Little OLEDs.jpg

Climate Sensing

Source code

Energy Monitoring

Source code

Multitasking

Jean-Francois Turcots SimpleTimer Library makes this fairly straightforward. It allows you to specify that any function run repeatedly (triggered independantly of whatever is going on in loop().

Add SimpleTimer to the lib_deps in yout platformio.ini file.

Example

 1 #include <SimpleTimer.h>
 2 
 3 // the timer object
 4 SimpleTimer timer;
 5 
 6 // functions to be executed periodically
 7 void repeatMe() {
 8     Serial.print("Uptime (s): ");
 9     Serial.println(millis() / 1000);
10 }
11 
12 void repeatMe2() {
13     Serial.print("Downtime (s): ");
14     Serial.println(millis() / 1000);
15 }
16 
17 void setup() {
18     Serial.begin(9600);
19     timer.setInterval(1000, repeatMe);   // Run RepeatMe() every 1000 miliseconds.
20     timer.setInterval(100, repeatMe);    // Run RepeatMe2() every 100 miliseconds.
21 }
22 
23 void loop() {
24     timer.run();
25 }

Modularization Tutorial (WIP)

The source code...