Skip to content

Commit 5a7f3a4

Browse files
authored
Add GatewayESP32OTA example (#1216)
1 parent 5d159a6 commit 5a7f3a4

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

.ci/arduino.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def buildMySensorsMicro(config, sketches, String key) {
5050
sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' &&
5151
sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' &&
5252
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
53+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
5354
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
5455
sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') {
5556
buildArduino(config, fqbn, sketches[sketch].path, key+'_MySensorsMicro')
@@ -85,6 +86,7 @@ def buildMySensorsGw(config, sketches, String key) {
8586
sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' &&
8687
sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' &&
8788
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
89+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
8890
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
8991
sketches[sketch].path != config.library_root+'examples/GatewaySerialRS485/GatewaySerialRS485.ino' &&
9092
sketches[sketch].path != config.library_root+'examples/MotionSensorRS485/MotionSensorRS485.ino') {
@@ -119,6 +121,7 @@ def buildArduinoUno(config, sketches, String key) {
119121
sketches[sketch].path != config.library_root+'examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino' &&
120122
sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' &&
121123
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
124+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
122125
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
123126
sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') {
124127
buildArduino(config, fqbn, sketches[sketch].path, key+'_ArduinoUno')
@@ -152,6 +155,7 @@ def buildArduinoMega(config, sketches, String key) {
152155
sketches[sketch].path != config.library_root+'examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino' &&
153156
sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' &&
154157
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
158+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
155159
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
156160
sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') {
157161
buildArduino(config, fqbn, sketches[sketch].path, key+'_ArduinoMega')
@@ -185,6 +189,7 @@ def buildSTM32F1(config, sketches, String key) {
185189
sketches[sketch].path != config.library_root+'examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino' &&
186190
sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' &&
187191
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
192+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
188193
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
189194
sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') {
190195
buildArduino(config, fqbn, sketches[sketch].path, key+'_STM32F1')
@@ -222,6 +227,7 @@ def buildESP8266(config, sketches, String key) {
222227
sketches[sketch].path != config.library_root+'examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino' &&
223228
sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' &&
224229
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
230+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
225231
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
226232
sketches[sketch].path != config.library_root+'examples/MotionSensorRS485/MotionSensorRS485.ino' &&
227233
sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino' &&
@@ -309,6 +315,7 @@ def buildnRF5(config, sketches, String key) {
309315
sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' &&
310316
sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' &&
311317
sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' &&
318+
sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' &&
312319
sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' &&
313320
sketches[sketch].path != config.library_root+'examples/GatewaySerialRS485/GatewaySerialRS485.ino' &&
314321
sketches[sketch].path != config.library_root+'examples/GatewayW5100/GatewayW5100.ino' &&
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
The MySensors Arduino library handles the wireless radio link and protocol
3+
between your home built sensors/actuators and HA controller of choice.
4+
The sensors forms a self healing radio network with optional repeaters. Each
5+
repeater and gateway builds a routing tables in EEPROM which keeps track of the
6+
network topology allowing messages to be routed to nodes.
7+
8+
Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
9+
Copyright (C) 2013-2018 Sensnology AB
10+
Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
11+
12+
Documentation: http://www.mysensors.org
13+
Support Forum: http://forum.mysensors.org
14+
15+
This program is free software; you can redistribute it and/or
16+
modify it under the terms of the GNU General Public License
17+
version 2 as published by the Free Software Foundation.
18+
19+
*******************************
20+
21+
REVISION HISTORY
22+
Version 1.0 - tekka
23+
Contribution by Berk
24+
25+
DESCRIPTION
26+
The ESP32 gateway sends data received from sensors to the WiFi link.
27+
The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
28+
29+
Make sure to fill in your ssid and WiFi password below.
30+
*/
31+
32+
// Enable debug prints to serial monitor
33+
#define MY_DEBUG
34+
35+
// Enables and select radio type (if attached)
36+
#define MY_RADIO_RF24
37+
//#define MY_RADIO_RFM69
38+
//#define MY_RADIO_RFM95
39+
40+
#define MY_GATEWAY_ESP32
41+
42+
#define MY_WIFI_SSID "MySSID"
43+
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
44+
45+
// Set the hostname for the WiFi Client. This is the hostname
46+
// it will pass to the DHCP server if not static.
47+
#define MY_HOSTNAME "ESP32_GW"
48+
49+
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
50+
//#define MY_IP_ADDRESS 192,168,1,100
51+
52+
// If using static ip you can define Gateway and Subnet address as well
53+
//#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
54+
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
55+
56+
// The port to keep open on node server mode
57+
#define MY_PORT 5003
58+
59+
// How many clients should be able to connect to this gateway (default 1)
60+
#define MY_GATEWAY_MAX_CLIENTS 2// Set blinking period
61+
62+
63+
// Advanced Gateway Options
64+
//#define MY_DEFAULT_LED_BLINK_PERIOD 50
65+
66+
// Flash leds on rx/tx/err
67+
// Led pins used if blinking feature is enabled above
68+
//#define MY_DEFAULT_ERR_LED_PIN 32 // Transfer data error led pin
69+
//#define MY_DEFAULT_RX_LED_PIN 25 // Receive Data led pin
70+
//#define MY_DEFAULT_TX_LED_PIN 27 // Transmit Data led pin
71+
72+
//#define MY_WITH_LEDS_BLINKING_INVERSE // At the time of Error, Receive, Transmit the pin is at a high level
73+
74+
75+
76+
#include <ArduinoOTA.h>
77+
#include <MySensors.h>
78+
79+
void setup()
80+
{
81+
// Setup locally attached sensors
82+
ArduinoOTA.onStart([]() {
83+
Serial.println("Start updating");
84+
});
85+
ArduinoOTA.onEnd([]() {
86+
Serial.println("\nEnd updating");
87+
});
88+
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
89+
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
90+
});
91+
ArduinoOTA.onError([](ota_error_t error) {
92+
Serial.printf("Error[%u]: ", error);
93+
if (error == OTA_AUTH_ERROR) {
94+
Serial.println("Auth Failed");
95+
} else if (error == OTA_BEGIN_ERROR) {
96+
Serial.println("Begin Failed");
97+
} else if (error == OTA_CONNECT_ERROR) {
98+
Serial.println("Connect Failed");
99+
} else if (error == OTA_RECEIVE_ERROR) {
100+
Serial.println("Receive Failed");
101+
} else if (error == OTA_END_ERROR) {
102+
Serial.println("End Failed");
103+
}
104+
});
105+
ArduinoOTA.begin();
106+
107+
108+
109+
// Setup locally attached sensors
110+
}
111+
112+
void presentation()
113+
{
114+
// Present locally attached sensors here
115+
}
116+
117+
void loop()
118+
{
119+
// Send locally attached sensors data here
120+
121+
ArduinoOTA.handle();
122+
}

0 commit comments

Comments
 (0)