Implement OTA update functionality with configuration and response handling; add necessary protobuf definitions and update main loop integration
This commit is contained in:
+31
-39
@@ -2,8 +2,11 @@
|
||||
#include <hardware_led.hpp>
|
||||
#include <hardware_rfid.hpp>
|
||||
#include <hardware_serial.hpp>
|
||||
#include <ota_update.hpp>
|
||||
#include "hardware.pb.h"
|
||||
|
||||
OtaUpdate ota;
|
||||
|
||||
// Demo for HardwareLed
|
||||
HardwareLed<2> led; // Assuming NeoPixel on pin 2 (D2 on ESP8266)
|
||||
|
||||
@@ -27,62 +30,51 @@ void onRfidTag(const hardware_SensorToControlMessage& msg) {
|
||||
void onSerialMessage(const IncomingMessage& msg) {
|
||||
if (msg.which_payload == hardware_ControlToSensorMessage_led_config_tag) {
|
||||
led.set(msg.payload.led_config);
|
||||
} else if (msg.which_payload == hardware_ControlToSensorMessage_ota_enable_tag) {
|
||||
hardware_SensorOTAEnableResponse response = {0};
|
||||
response.success = ota.configure(msg.payload.ota_enable);
|
||||
if (response.success) {
|
||||
IPAddress ip = WiFi.localIP();
|
||||
if (!msg.payload.ota_enable.as_station_mode) {
|
||||
ip = WiFi.softAPIP();
|
||||
}
|
||||
strcpy(response.ip_address, ip.toString().c_str());
|
||||
} else {
|
||||
strcpy(response.error_message, "Failed to configure OTA");
|
||||
}
|
||||
|
||||
hardware_SensorToControlMessage responseMsg = {0};
|
||||
responseMsg.sensor_id = msg.control_id; // or some id
|
||||
responseMsg.which_payload = hardware_SensorToControlMessage_ota_response_tag;
|
||||
responseMsg.payload.ota_response = response;
|
||||
|
||||
serial.sendMessage(responseMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
led.begin();
|
||||
rfid.begin();
|
||||
rfid.setCallback(onRfidTag);
|
||||
serial.begin(Serial);
|
||||
serial.setCallback(onSerialMessage);
|
||||
|
||||
// // Static config
|
||||
// configs[0] = {0};
|
||||
// configs[0].brightness = 128;
|
||||
// configs[0].duration_ms = 0;
|
||||
// configs[0].which_animation_params = 3;
|
||||
// configs[0].animation_params.static_params.color = 0x00FF00; // Green
|
||||
// Static config
|
||||
configs[0] = {0};
|
||||
configs[0].brightness = 128;
|
||||
configs[0].duration_ms = 0;
|
||||
configs[0].which_animation_params = 3;
|
||||
configs[0].animation_params.static_params.color = 0x00FF00; // Green
|
||||
|
||||
// // Pulse config
|
||||
// configs[1] = {0};
|
||||
// configs[1].brightness = 128;
|
||||
// configs[1].duration_ms = 0;
|
||||
// configs[1].which_animation_params = 4;
|
||||
// configs[1].animation_params.pulse_params.color = 0xFF0000; // Red
|
||||
// configs[1].animation_params.pulse_params.speed_ms = 500;
|
||||
|
||||
// // Fade config
|
||||
// configs[2] = {0};
|
||||
// configs[2].brightness = 128;
|
||||
// configs[2].duration_ms = 0;
|
||||
// configs[2].which_animation_params = 5;
|
||||
// configs[2].animation_params.fade_params.colors_count = 3;
|
||||
// configs[2].animation_params.fade_params.colors[0] = 0xFF0000; // Red
|
||||
// configs[2].animation_params.fade_params.colors[1] = 0x00FF00; // Green
|
||||
// configs[2].animation_params.fade_params.colors[2] = 0x0000FF; // Blue
|
||||
// configs[2].animation_params.fade_params.speed_ms = 1000;
|
||||
|
||||
// // Flicker config
|
||||
// configs[3] = {0};
|
||||
// configs[3].brightness = 128;
|
||||
// configs[3].duration_ms = 0;
|
||||
// configs[3].which_animation_params = 6;
|
||||
// configs[3].animation_params.flicker_params.color = 0xFFFFFF; // White
|
||||
// configs[3].animation_params.flicker_params.intensity = 50;
|
||||
|
||||
// led.set(configs[0]);
|
||||
led.set(configs[0]);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
led.update();
|
||||
rfid.update();
|
||||
serial.update();
|
||||
|
||||
// if (millis() - lastChange >= 10000) {
|
||||
// lastChange = millis();
|
||||
// currentConfig = (currentConfig + 1) % 4;
|
||||
// led.set(configs[currentConfig]);
|
||||
// }
|
||||
ota.update();
|
||||
}
|
||||
Reference in New Issue
Block a user