Difference between revisions of "TinyOTA"

From The TinkerNet Wiki
Jump to navigation Jump to search
Line 50: Line 50:
 
#include <Arduino.h>
 
#include <Arduino.h>
  
/*
+
#include "Functions.h"
  To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update
 
*/
 
 
 
#if MPU == ESP8266
 
#include <ESP8266WebServer.h>
 
#include <ESP8266HTTPUpdateServer.h>
 
 
 
ESP8266WebServer httpServer(80);
 
ESP8266HTTPUpdateServer httpUpdater;
 
#elif MPU == ESP32
 
#include <WebServer.h>
 
#include <HTTPUpdateServer.h>
 
 
 
WebServer httpServer(80);
 
HTTPUpdateServer httpUpdater;
 
#endif
 
 
 
void WiFi_Setup();
 
 
 
 
 
 
 
String TestPage =
 
    "<H1>This</H1>"
 
    "<H2>is only a</H2>"
 
    "<H1>TEST!</H1>"
 
    "<a href='/update'>Update Page</a>";
 
void handleRootPath();
 
 
 
void setup(void) {
 
  
 +
void setup(void)
 +
{
 
   Serial.begin(115200);
 
   Serial.begin(115200);
 
   Serial.println();
 
   Serial.println();
   Serial.println("Booting Sketch...");
+
   Serial.println("Booting Up...");
 
 
WiFi_Setup();
 
 
 
  httpUpdater.setup(&httpServer);
 
  httpServer.begin();
 
  
httpServer.on("/", handleRootPath);
+
  WiFi_Setup();
 
+
   HTTP_Setup();
   Serial.printf("HTTPUpdateServer ready! Open http://%s/update in your browser\n", WiFi.localIP().toString().c_str());
+
  Actual_Setup();
}
 
  
void loop(void) {
+
   Serial.println("Ready...");
   httpServer.handleClient();
 
 
}
 
}
  
void handleRootPath() {
+
void loop(void)
+
{
   //  httpServer.send(200, "text/plain", "Hello world");
+
   HTTP_loop();
  httpServer.send(200, "text/html", TestPage);
+
  Actual_loop();
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 21:11, 7 May 2021

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:ESP32]
10 platform = espressif32
11 board = fm-devkit
12 framework = arduino
13 monitor_speed = 115200
14 build_flags =
15     -D MPU=ESP32
16 
17 [env:M3]                                    ; THIS ONE ACTUALLY WORKS!!!
18 platform = espressif8266
19 board = d1_mini
20 framework = arduino
21 monitor_speed = 115200
22 board_build.ldscript = eagle.flash.1m.ld
23 build_flags =
24     -D MPU=ESP8266
25 
26 [env:oops]                                  ; Use this one to "Monitor" if something borks...
27 platform = espressif8266
28 board = d1_mini
29 framework = arduino
30 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 <Arduino.h>
 2 
 3 #include "Functions.h"
 4 
 5 void setup(void)
 6 {
 7   Serial.begin(115200);
 8   Serial.println();
 9   Serial.println("Booting Up...");
10 
11   WiFi_Setup();
12   HTTP_Setup();
13   Actual_Setup();
14 
15   Serial.println("Ready...");
16 }
17 
18 void loop(void)
19 {
20   HTTP_loop();
21   Actual_loop();
22 }

WiFi.cpp

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