TinyOTA

From The TinkerNet Wiki
Revision as of 18:01, 7 May 2021 by Tinker (talk | contribs) (Created page with "==platformio.ini== <syntaxhighlight lang="ini" line="1"> [env:d1_mini_lite] platform = espressif8266 board = d1_mini_lite framework = arduino monitor_speed = 115200 build_fla...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

platformio.ini

 1 [env:d1_mini_lite]
 2 platform = espressif8266
 3 board = d1_mini_lite
 4 framework = arduino
 5 monitor_speed = 115200
 6 build_flags =
 7     -D MPU=ESP8266
 8 
 9 [env:M3]
10 platform = espressif8266
11 board = d1_mini
12 framework = arduino
13 monitor_speed = 115200
14 board_build.ldscript = eagle.flash.2m.ld
15 build_flags =
16     -D MPU=ESP8266
17 
18 [env:M3b]                         // THIS ONE ACTUALLY WORKS!!!
19 platform = espressif8266
20 board = d1_mini
21 framework = arduino
22 monitor_speed = 115200
23 board_build.ldscript = eagle.flash.1m.ld
24 build_flags =
25     -D MPU=ESP8266
26 
27 [env:oops]
28 platform = espressif8266
29 board = d1_mini
30 framework = arduino
31 monitor_speed = 78400


#includes, Defines, etc...

TopSecret.h

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

The Code Itself

main.cpp

 1 #include <ESP8266WebServer.h>
 2 #include <ESP8266HTTPUpdateServer.h>
 3 
 4 void WiFi_Setup();
 5 
 6 
 7 ESP8266WebServer httpServer(80);
 8 ESP8266HTTPUpdateServer httpUpdater;
 9 
10 String TestPage =
11     "<H1>This</H1>"
12     "<H2>is only a</H2>"
13     "<H1>TEST!</H1>"
14     "<a href='/update'>Update Page</a>";
15 void handleRootPath();
16 
17 void setup(void) {
18 
19   Serial.begin(115200);
20   Serial.println();
21   Serial.println("Booting Sketch...");
22 
23 WiFi_Setup();
24 
25   httpUpdater.setup(&httpServer);
26   httpServer.begin();
27 
28 httpServer.on("/", handleRootPath);
29 
30   Serial.printf("HTTPUpdateServer ready! Open http://%s/update in your browser\n", WiFi.localIP().toString().c_str());
31 }
32 
33 void loop(void) {
34   httpServer.handleClient();
35 }
36 
37 void handleRootPath() {
38  
39    httpServer.send(200, "text/plain", "Hello world");
40  
41 }

WiFi.cpp

 1 #if MPU == ESP8266
 2 #include <ESP8266WiFi.h>
 3 #include <WiFiClient.h>
 4 
 5 // #include <ESPAsyncTCP.h>
 6 // const char *MPUtype = "ESP8266";
 7 #elif MPU == ESP32
 8 #include <WiFi.h>
 9 #include <WiFiClient.h>
10 // #include <ESPmDNS.h>
11 // const char *MPUtype = "ESP32";
12 #endif
13 
14 #include "TopSecret.h"
15 
16 void WiFi_Setup()
17 {
18   WiFi.mode(WIFI_STA);
19   WiFi.begin(ssid, password);
20 
21   // Wait for connection
22   while (WiFi.status() != WL_CONNECTED)
23   {
24     delay(500);
25     Serial.print(".");
26   }
27   Serial.println("");
28   Serial.printf("Connected to %s\n", ssid);
29   Serial.printf("IP address: %s\n", WiFi.localIP().toString().c_str());
30 }