MySensors Library & Examples  2.3.2
GatewayESP32OTA.ino
1 
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 // passed 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 #include <ArduinoOTA.h>
75 #include <MySensors.h>
76 
77 void setup()
78 {
79  // Setup locally attached sensors
80  ArduinoOTA.onStart([]() {
81  Serial.println("Start updating");
82  });
83  ArduinoOTA.onEnd([]() {
84  Serial.println("\nEnd updating");
85  });
86  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
87  Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
88  });
89  ArduinoOTA.onError([](ota_error_t error) {
90  Serial.printf("Error[%u]: ", error);
91  if (error == OTA_AUTH_ERROR) {
92  Serial.println("Auth Failed");
93  } else if (error == OTA_BEGIN_ERROR) {
94  Serial.println("Begin Failed");
95  } else if (error == OTA_CONNECT_ERROR) {
96  Serial.println("Connect Failed");
97  } else if (error == OTA_RECEIVE_ERROR) {
98  Serial.println("Receive Failed");
99  } else if (error == OTA_END_ERROR) {
100  Serial.println("End Failed");
101  }
102  });
103  ArduinoOTA.begin();
104 
105 
106 
107  // Setup locally attached sensors
108 }
109 
111 {
112  // Present locally attached sensors here
113 }
114 
115 void loop()
116 {
117  // Send locally attached sensors data here
118 
119  ArduinoOTA.handle();
120 }
loop
void loop()
Main loop.
Definition: GatewayESP32OTA.ino:115
presentation
void presentation()
Node presentation.
Definition: GatewayESP32OTA.ino:110
setup
void setup()
Called after node initialises but before main loop.
Definition: GatewayESP32OTA.ino:77
MySensors.h
API declaration for MySensors.