Refactor payload creation out of EspNowLightControlClient
This commit is contained in:
parent
fe4c631192
commit
9338787b54
2 changed files with 25 additions and 18 deletions
|
@ -30,23 +30,13 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
void send() {
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
LightControlPayload data = LightControlPayload();
|
||||
data.id = i;
|
||||
data.brightness = 1;
|
||||
data.on = false;
|
||||
data.timer = 0;
|
||||
|
||||
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t*)&data, sizeof(data));
|
||||
if (result == ESP_OK)
|
||||
Serial.println("Sent with success");
|
||||
else {
|
||||
Serial.println("Error sending the data");
|
||||
Serial.println(esp_err_to_name(result));
|
||||
}
|
||||
|
||||
delay(100);
|
||||
void send(LightControlPayload data) {
|
||||
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t*)&data, sizeof(data));
|
||||
if (result == ESP_OK)
|
||||
Serial.println("Sent with success");
|
||||
else {
|
||||
Serial.println("Error sending the data");
|
||||
Serial.println(esp_err_to_name(result));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,13 +1,30 @@
|
|||
#include <Arduino.h>
|
||||
#include "EspNowLightControlClient.cpp"
|
||||
#include "LightControlPayload.cpp"
|
||||
|
||||
EspNowLightControlClient _control;
|
||||
|
||||
void sendOffCommands() {
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
LightControlPayload data = LightControlPayload();
|
||||
data.id = i;
|
||||
data.brightness = 1;
|
||||
data.on = false;
|
||||
data.timer = 0;
|
||||
|
||||
_control.send(data);
|
||||
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
_control.init();
|
||||
_control.send();
|
||||
|
||||
sendOffCommands();
|
||||
sendOffCommands(); // do it again because sometimes once isn't enough
|
||||
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue