From 3ec999cd8de15fc8db91a2ca7fbdc08645badbe2 Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 23 Jan 2023 06:17:23 -0600 Subject: [PATCH] Create RemoteDevice8286.ino --- .../RemoteDevice8286/RemoteDevice8286.ino | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/Other Examples/RemoteSensors/RemoteDevice8286/RemoteDevice8286.ino diff --git a/examples/Other Examples/RemoteSensors/RemoteDevice8286/RemoteDevice8286.ino b/examples/Other Examples/RemoteSensors/RemoteDevice8286/RemoteDevice8286.ino new file mode 100644 index 0000000..0db15bb --- /dev/null +++ b/examples/Other Examples/RemoteSensors/RemoteDevice8286/RemoteDevice8286.ino @@ -0,0 +1,51 @@ + +#include +#include +#include + +float temp=-10.0; + +uint8_t main_mac[6]={0x84,0xCC,0xA8,0x11,0xB4,0x85}; + +void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) { + Serial.printf("Last Packet Send Status: %s\n",sendStatus==0?"Success":"Fail"); +} + +void setup() { + + Serial.begin(115200); + delay(1000); + Serial.printf("\nMAC Address: %s\n",WiFi.macAddress().c_str()); + + WiFi.mode(WIFI_STA); + wifi_set_channel(6); + + if (esp_now_init() != 0) { + Serial.println("Error initializing ESP-NOW"); + return; + } + + uint8_t hash[32]; + char password[]="HomeSpan"; + + experimental::crypto::SHA256::hash(password,strlen(password),hash); + + esp_now_register_send_cb(OnDataSent); + esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER); + + esp_now_set_kok(hash+16,16); + + esp_now_add_peer(main_mac, ESP_NOW_ROLE_COMBO, 0, hash, 16); +} + +void loop() { + + Serial.printf("Sending Temperature: %f\n",temp); + esp_now_send(main_mac, (uint8_t *)&temp, sizeof(temp)); + + temp+=0.5; + if(temp>35.0) + temp=-10.0; + + delay(5000); +}