Skip to content

Commit e716251

Browse files
committed
Enabled OTA uploading, ditched mDns lib because ArduinoOta hanldes it
1 parent 4a8a0eb commit e716251

File tree

8 files changed

+76
-14
lines changed

8 files changed

+76
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ The hardware provides all the electronics needed and allows different boards to
99
## the current team
1010
The team is composed of a programmer ([Simon](https://github.com/simonjamain)) and two electronitians (Romain & Marcellin), all french airsofters.
1111

12-
## installation
12+
## installation and build
1313
- Install platformio
1414
- "open" the project
1515
- for building the ui (mandatory) :
1616
- install node.js
1717
- inside the `ui` folder, run `npm install`
1818
- *Note : `ui.h` is recompiled by running the command `npm run build` inside the `ui` folder. this is done automaticaly before each platformio build (see platformio.ini and build_ui.py)*
19+
- OTA upload is enabled by default, if your board hasnt ota enabled or you want to upload with serial, uncomment that following parameters in `platformio.ini`
20+
- `upload_protocol`
21+
- `upload_port`
1922
- I think thats about it...
2023

2124
## hardware

platformio.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
[env:esp32doit-devkit-v1]
1212
platform = espressif32
1313
board = esp32doit-devkit-v1
14-
upload_speed = 921600
1514
monitor_speed = 115200
15+
upload_speed = 921600
16+
; comment line below for serial upload
17+
upload_protocol = espota
18+
; comment line below for serial upload
19+
upload_port = openmosfet.local
1620
framework = arduino
1721
build_flags =
1822
-D DEBUG

src/config.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88
//---------- X : Global default parameters ---------------------------------------------------------------------------------------
99

1010
#define OM_CONFIGFILE_NAME "/cfg.json"
11-
#define OM_DEFAULT_APSSID "OpenMosfet"//Note : must be [OM_WIFI_SSID_MIN_SIZE-OM_WIFI_SSID_MAX_SIZE] character (exluding '\0') in order to work
12-
#define OM_DEFAULT_APP_PASSWD "password"//Note : must be [OM_WIFI_PSSWD_MIN_SIZE-OM_WIFI_PSSWD_MAX_SIZE] character (exluding '\0') in order to work
13-
//#define OM_DEFAULT_APSSID {'o','p','e','n','M','o','s','f','e','t','\0'}//Note : must be [8-32] character (exluding '\0') in order to work
14-
//#define OM_DEFAULT_APP_PASSWD {'p','a','s','s','w','o','r','d','\0'}//Note : must be [8-16] character (exluding '\0') in order to work
11+
#define OM_DEFAULT_APSSID "OpenMosfet"//Note : must be [OM_WIFI_SSID_MIN_SIZE-OM_WIFI_SSID_MAX_SIZE] character in order to work
12+
#define OM_DEFAULT_APP_PASSWD "password"//Note : must be [OM_WIFI_PSSWD_MIN_SIZE-OM_WIFI_PSSWD_MAX_SIZE] character in order to work
1513

1614
#define OM_DEFAULT_AVAILABLE_NETWORK_APSSID "externalssid"//Note : must be [OM_WIFI_SSID_MIN_SIZE-OM_WIFI_SSID_MAX_SIZE] character (exluding '\0') in order to work
1715
#define OM_DEFAULT_AVAILABLE_NETWORK_APP_PASSWD "externalpassword"//Note : must be [OM_WIFI_PSSWD_MIN_SIZE-OM_WIFI_PSSWD_MAX_SIZE] character (exluding '\0') in order to work
1816

19-
2017
#define OM_DEFAULT_WIFI_SEARCH_TIMEOUT_SECONDS 5
2118
#define OM_DEFAULT_WIFI_SHUTDOWN_DELAY_MINUTES 15
2219
#define OM_DEFAULT_DEEP_SLEEP_DELAY_MINUTES 60

src/openmosfet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "components.h"
77
#include "configuration.h"
88
#include "wifiServer.h"
9+
#include "otaUploader.h"
910

1011
OMVirtualReplica replica;
1112

@@ -46,12 +47,12 @@ void setup() {
4647
OMConfiguration::load();
4748

4849
OMwifiserver::begin();
50+
OMOtaUploader::begin();
4951
}
5052

5153
void loop() {
52-
5354
OMwifiserver::update();
54-
replica.update();
55+
OMOtaUploader::update();
5556
OMInputsInterface::update(replica);
56-
57+
replica.update();
5758
}

src/otaUploader.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <ArduinoOTA.h>
2+
3+
#include "otaUploader.h"
4+
5+
void OMOtaUploader::begin()
6+
{
7+
ArduinoOTA.setPort(3232);
8+
ArduinoOTA.setHostname("openmosfet");
9+
10+
ArduinoOTA.onStart([]() {
11+
String type;
12+
if (ArduinoOTA.getCommand() == U_FLASH)
13+
type = "sketch";
14+
else // U_SPIFFS
15+
type = "filesystem";
16+
17+
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
18+
Serial.println("Start updating " + type);
19+
})
20+
.onEnd([]() {
21+
Serial.println("\nEnd");
22+
})
23+
.onProgress([](unsigned int progress, unsigned int total) {
24+
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
25+
})
26+
.onError([](ota_error_t error) {
27+
Serial.printf("Error[%u]: ", error);
28+
if (error == OTA_AUTH_ERROR)
29+
Serial.println("Auth Failed");
30+
else if (error == OTA_BEGIN_ERROR)
31+
Serial.println("Begin Failed");
32+
else if (error == OTA_CONNECT_ERROR)
33+
Serial.println("Connect Failed");
34+
else if (error == OTA_RECEIVE_ERROR)
35+
Serial.println("Receive Failed");
36+
else if (error == OTA_END_ERROR)
37+
Serial.println("End Failed");
38+
});
39+
40+
ArduinoOTA.begin();
41+
}
42+
43+
void OMOtaUploader::update()
44+
{
45+
ArduinoOTA.handle();
46+
}

src/otaUploader.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef OTA_UPLOADER_H
2+
#define OTA_UPLOADER_H
3+
4+
#include <Arduino.h>
5+
#include "components.h"
6+
7+
class OMOtaUploader
8+
{
9+
public:
10+
11+
static void begin();
12+
static void update();
13+
};
14+
15+
#endif

src/wifiServer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ void OMwifiserver::begin()
5252
}
5353
}
5454

55-
if(!MDNS.begin("openmosfet")) {
56-
Serial.println("Error starting mDNS");
57-
}
5855
}
5956
/* You can remove the password parameter if you want the AP to be open. */
6057
WiFi.softAP(OMConfiguration::appSsid, OMConfiguration::appPasswd);

src/wifiServer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <WiFiClient.h>
1111
#include <WiFiAP.h>
1212
#include <DNSServer.h>
13-
#include <ESPmDNS.h>
1413
#include <AsyncTCP.h>
1514
#include <ESPAsyncWebServer.h>
1615
#include <AsyncJson.h>

0 commit comments

Comments
 (0)