Difference between revisions of "Adding OTA"

From The TinkerNet Wiki
Jump to navigation Jump to search
(Created page with "So... You've created the most awesomest IoT device ever... & you're gonna sell a million... Whatcha gonna do when you find a bug?")
 
Line 6: Line 6:
  
 
Whatcha gonna do when you find a bug?
 
Whatcha gonna do when you find a bug?
 +
 +
= Current state of OTA in my '''Modular Firmware''' =
 +
 +
==platformio.ini==
 +
 +
<syntaxhighlight lang="ini" line="1">
 +
[env:ESP32]
 +
platform = espressif32
 +
board = fm-devkit
 +
framework = arduino
 +
monitor_speed = 115200
 +
lib_deps =
 +
    AsyncElegantOTA
 +
    ESPAsyncTCP
 +
    ESP Async WebServer
 +
build_flags =
 +
    -D MPU=ESP32
 +
 +
[env:ESP8266]
 +
platform = espressif8266
 +
board = d1_mini
 +
framework = arduino
 +
monitor_speed = 115200
 +
lib_deps =
 +
    AsyncElegantOTA
 +
    ESPAsyncTCP
 +
    ESP Async WebServer
 +
build_flags =
 +
    -D MPU=ESP8266
 +
</syntaxhighlight>
 +
 +
==#includes, Defines, etc...==
 +
 +
===TopSecret.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
const char *host = "Device Name";
 +
const char *ssid = "SSID";
 +
const char *password = "Password";
 +
</syntaxhighlight>
 +
 +
===libraries.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
#ifndef LIBRARIES_H
 +
#define LIBRARIES_H
 +
 +
// WiFi ////////////////////////////////////////////////////////////////////////
 +
#if MPU == ESP8266
 +
#include <ESP8266WiFi.h>
 +
#elif MPU == ESP32
 +
#include <WiFi.h>
 +
#endif
 +
 +
#endif // LIBRARIES_H
 +
</syntaxhighlight>
 +
 +
===functions.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
// OTA /////////////////////////////////////////////////////////////////////////
 +
 +
void WiFi_Setup();
 +
void OTA_init();
 +
void OTA_Loop();
 +
void Actual_Setup();
 +
void Actual_Loop();
 +
 +
// Debug ///////////////////////////////////////////////////////////////////////
 +
void debug_TitleScreen();                  // Title block for the project
 +
void debug_ReadyScreen();                  // Indicate setup is finished
 +
void debug_Separator();                    // Make a line
 +
void debug_SectionTitle(const char *Title); // Text at the left
 +
void debug_LineOut(const char *Line);      // Text 3 characters inset
 +
void debug_Action(const char *Line);        // Text centred
 +
void debug_Trouble(const char *Line);      //
 +
void debug_Success(const char *Line);      //
 +
void debug_ProgressBar0();
 +
void debug_ProgressBar1();
 +
void debug_ProgressBar2(int dotcount);
 +
void debug_ESP_info();
 +
</syntaxhighlight>
 +
 +
===debug.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
const char DeviceName[] = "ESP Web OTA";
 +
const char DeviceDesc[] = "ESP Web OTA";
 +
</syntaxhighlight>
 +
 +
===OTA_Web.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
#ifndef OTA_WEB_H
 +
#define OTA_WEB_H
 +
 +
#include "OTA_poop.h"
 +
 +
/* Style */
 +
String style =
 +
    "<style>"
 +
    "#file-input,"
 +
    "input{width:100%;height:44px;border-radius:4px;margin:10px auto;font-size:15px}"
 +
    "input{background:#f1f1f1;border:0;padding:0 15px}"
 +
 +
    "body{background:#004400;font-family:sans-serif;font-size:14px;color:#777}"
 +
 +
    "#file-input{padding:0;border:1px solid #ddd;line-height:44px;text-align:left;display:block;cursor:pointer}"
 +
    "#bar,"
 +
    "#prgbar{background-color:#f1f1f1;border-radius:10px}"
 +
 +
    "#bar{background-color:#3498db;width:0%;height:10px}"
 +
    "form{background:#fff;max-width:512px;margin:75px auto;padding:30px;border-radius:5px;text-align:center}"
 +
    ".btn{background:#660066;color:#fff;cursor:pointer}"
 +
    "</style>";
 +
 +
/* Login page */
 +
String RootPage =
 +
    "<form name=loginForm>"
 +
    "<h1>"
 +
    // + Type +
 +
    // " "
 +
    + sDeviceName +
 +
    // " "
 +
    // + DeviceName +
 +
    " </h1>"
 +
    "<input type=submit "
 +
    "onclick=window.open('/update')"
 +
    " class=btn value=Update>"
 +
 +
    "<input type=submit "
 +
    "onclick=check(this.form)"
 +
    " class=btn value=Downdate>"
 +
 +
    "<input type=submit "
 +
    "onclick=puke(this.form)"
 +
    " class=btn value=Maybe>"
 +
 +
    "</form>"
 +
    "<script>"
 +
    "function check(form) {"
 +
    "{window.open('/Test', '_self')}"
 +
    "}"
 +
    "</script>"
 +
 +
    "<script>"
 +
    "function puke(form) {"
 +
    // "{window.open(\"/Test\", \"_self\")}"
 +
    "{window.open(\"/Test\")}"
 +
    "}"
 +
    "</script>" +
 +
    style;
 +
 +
String TestPage =
 +
    "<H1>This</H1>"
 +
    "<H2>is only a</H2>"
 +
    "<H1>TEST!</H1>";
 +
#endif // OTA_WEB_H
 +
</syntaxhighlight>
 +
 +
===OTA_poop.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
const char* OTAuser = "root";
 +
const char* OTApass = "F00Bar!";
 +
 +
#ifdef SS_Alert
 +
const String sDeviceName = "SugarShack PumpHouse Alerter";
 +
 +
#elif SS_PHTank
 +
const String sDeviceName = "SugarShack PumpHouse Tank Monitor";
 +
 +
#elif SS_PHLightBar
 +
const String sDeviceName = "SugarShack PumpHouse LightBar Driver";
 +
 +
#elif SS_Dumper
 +
const String sDeviceName = "SugarShack PumpHouse Dumper Monitor";
 +
 +
#elif SS_RO
 +
const String sDeviceName = "SugarShack Reverse-Osmosis Unit Monitor";
 +
 +
#elif SS_Evaporator
 +
const String sDeviceName = "SugarShack Evaporator Monitor";
 +
 +
#elif SS_BottlingTank
 +
const String sDeviceName = "SugarShack Bottling Tank Monitor";
 +
 +
#elif SS_Climate
 +
const String sDeviceName = "SugarShack Climate Monitor";
 +
 +
#elif SS_HoldingTanks
 +
const String sDeviceName = "SugarShack Holding Tank Monitor";
 +
 +
#elif SS_FeedTank
 +
const String sDeviceName = "SugarShack Feed Tank Monitor";
 +
 +
#else
 +
const String sDeviceName = "NFC What this one is...";
 +
#endif // FOOBAR
 +
</syntaxhighlight>
 +
 +
===ActualStuff.h===
 +
<syntaxhighlight lang="cpp" line="1">
 +
void ActualSetup();
 +
void ActualLoop();
 +
</syntaxhighlight>

Revision as of 19:51, 6 May 2021

So...

You've created the most awesomest IoT device ever...

& you're gonna sell a million...

Whatcha gonna do when you find a bug?

Current state of OTA in my Modular Firmware

platformio.ini

 1 [env:ESP32]
 2 platform = espressif32
 3 board = fm-devkit
 4 framework = arduino
 5 monitor_speed = 115200
 6 lib_deps =
 7     AsyncElegantOTA
 8     ESPAsyncTCP
 9     ESP Async WebServer
10 build_flags =
11     -D MPU=ESP32
12 
13 [env:ESP8266]
14 platform = espressif8266
15 board = d1_mini
16 framework = arduino
17 monitor_speed = 115200
18 lib_deps =
19     AsyncElegantOTA
20     ESPAsyncTCP
21     ESP Async WebServer
22 build_flags =
23     -D MPU=ESP8266

#includes, Defines, etc...

TopSecret.h

1 const char *host = "Device Name";
2 const char *ssid = "SSID";
3 const char *password = "Password";

libraries.h

 1 #ifndef LIBRARIES_H
 2 #define LIBRARIES_H
 3 
 4 // WiFi ////////////////////////////////////////////////////////////////////////
 5 #if MPU == ESP8266
 6 #include <ESP8266WiFi.h>
 7 #elif MPU == ESP32
 8 #include <WiFi.h>
 9 #endif
10 
11 #endif // LIBRARIES_H

functions.h

 1 // OTA /////////////////////////////////////////////////////////////////////////
 2 
 3 void WiFi_Setup();
 4 void OTA_init();
 5 void OTA_Loop();
 6 void Actual_Setup();
 7 void Actual_Loop();
 8 
 9 // Debug ///////////////////////////////////////////////////////////////////////
10 void debug_TitleScreen();                   // Title block for the project
11 void debug_ReadyScreen();                   // Indicate setup is finished
12 void debug_Separator();                     // Make a line
13 void debug_SectionTitle(const char *Title); // Text at the left
14 void debug_LineOut(const char *Line);       // Text 3 characters inset
15 void debug_Action(const char *Line);        // Text centred
16 void debug_Trouble(const char *Line);       //
17 void debug_Success(const char *Line);       //
18 void debug_ProgressBar0();
19 void debug_ProgressBar1();
20 void debug_ProgressBar2(int dotcount);
21 void debug_ESP_info();

debug.h

1 const char DeviceName[] = "ESP Web OTA";
2 const char DeviceDesc[] = "ESP Web OTA";

OTA_Web.h

 1 #ifndef OTA_WEB_H
 2 #define OTA_WEB_H
 3 
 4 #include "OTA_poop.h"
 5 
 6 /* Style */
 7 String style =
 8     "<style>"
 9     "#file-input,"
10     "input{width:100%;height:44px;border-radius:4px;margin:10px auto;font-size:15px}"
11     "input{background:#f1f1f1;border:0;padding:0 15px}"
12 
13     "body{background:#004400;font-family:sans-serif;font-size:14px;color:#777}"
14 
15     "#file-input{padding:0;border:1px solid #ddd;line-height:44px;text-align:left;display:block;cursor:pointer}"
16     "#bar,"
17     "#prgbar{background-color:#f1f1f1;border-radius:10px}"
18 
19     "#bar{background-color:#3498db;width:0%;height:10px}"
20     "form{background:#fff;max-width:512px;margin:75px auto;padding:30px;border-radius:5px;text-align:center}"
21     ".btn{background:#660066;color:#fff;cursor:pointer}"
22     "</style>";
23 
24 /* Login page */
25 String RootPage =
26     "<form name=loginForm>"
27     "<h1>"
28     // + Type +
29     // " "
30     + sDeviceName +
31     // " "
32     // + DeviceName +
33     " </h1>"
34     "<input type=submit "
35     "onclick=window.open('/update')"
36     " class=btn value=Update>"
37 
38     "<input type=submit "
39     "onclick=check(this.form)"
40     " class=btn value=Downdate>"
41 
42     "<input type=submit "
43     "onclick=puke(this.form)"
44     " class=btn value=Maybe>"
45 
46     "</form>"
47     "<script>"
48     "function check(form) {"
49     "{window.open('/Test', '_self')}"
50     "}"
51     "</script>"
52 
53     "<script>"
54     "function puke(form) {"
55     // "{window.open(\"/Test\", \"_self\")}"
56     "{window.open(\"/Test\")}"
57     "}"
58     "</script>" +
59     style;
60 
61 String TestPage =
62     "<H1>This</H1>"
63     "<H2>is only a</H2>"
64     "<H1>TEST!</H1>";
65 #endif // OTA_WEB_H

OTA_poop.h

 1 const char* OTAuser = "root";
 2 const char* OTApass = "F00Bar!";
 3 
 4 #ifdef SS_Alert
 5 const String sDeviceName = "SugarShack PumpHouse Alerter";
 6 
 7 #elif SS_PHTank
 8 const String sDeviceName = "SugarShack PumpHouse Tank Monitor";
 9 
10 #elif SS_PHLightBar
11 const String sDeviceName = "SugarShack PumpHouse LightBar Driver";
12 
13 #elif SS_Dumper
14 const String sDeviceName = "SugarShack PumpHouse Dumper Monitor";
15 
16 #elif SS_RO
17 const String sDeviceName = "SugarShack Reverse-Osmosis Unit Monitor";
18 
19 #elif SS_Evaporator
20 const String sDeviceName = "SugarShack Evaporator Monitor";
21 
22 #elif SS_BottlingTank
23 const String sDeviceName = "SugarShack Bottling Tank Monitor";
24 
25 #elif SS_Climate
26 const String sDeviceName = "SugarShack Climate Monitor";
27 
28 #elif SS_HoldingTanks
29 const String sDeviceName = "SugarShack Holding Tank Monitor";
30 
31 #elif SS_FeedTank
32 const String sDeviceName = "SugarShack Feed Tank Monitor";
33 
34 #else
35 const String sDeviceName = "NFC What this one is...";
36 #endif // FOOBAR

ActualStuff.h

1 void ActualSetup();
2 void ActualLoop();