Skip to content
Snippets Groups Projects
Commit a05e8c34 authored by Moritz Perschke's avatar Moritz Perschke
Browse files

host-> client response functionality added

parent 415aed45
No related branches found
No related tags found
4 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!5fipy host broadcasts its mac + timestamp on start, main function of client...
......@@ -31,11 +31,15 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
if (!preferences.isKey("host")) {
preferences.putBytes("host", new_config.host, sizeof(new_config.host));
Serial.println("host mac saved to flash");
} // host change shouldn't be an issue
} else{
Serial.println("host mac already exists");
}// host change shouldn't be an issue
preferences.end();
// sync time
esptime::rtc.setTime(
new_config.time_millis); // see https://www.esp32.com/viewtopic.php?t=9965, maybe this needs an offset
Serial.println("Saved Time: " + (String) new_config.time_millis);
Serial.flush();
}
esp_err_t espnow_setup()
......
......@@ -25,8 +25,8 @@ esp_err_t Message::send()
Serial.println((String) "time sent: " + data.timestamp);
Serial.println((String) "Send status: " + success);
Serial.println();
Serial.flush();
Serial.println("done");
Serial.flush();
return success;
}
......
......@@ -2,6 +2,7 @@
#include "ram_caching.hpp"
#include <Arduino.h>
#include <ArduinoJson.h>
#include "Time.hpp"
void setup()
{
......@@ -41,5 +42,8 @@ void loop()
// resend_message->send();
// delete resend_message;
// }
Serial.println("Current Time: " + (String) esptime::rtc.getMillis());
Serial.println("delaying...");
Serial.flush();
delay(5000);
}
\ No newline at end of file
# main.py -- put your code here!
from network import WLAN
from network import ESPNOW
from pycom import rgbled
# from network import ESPNOW
import binascii
import struct
from time import sleep
from lib.server_transfer import DataTransferWiFi
def bytes_to_data(msg):
# turn bytes from message into 22-tuple of integers(identifiers), floats(values), integer(amount) and long(timestamp)
data = struct.unpack("<10i10fil", bytes(msg))
amountData = data[20]
timestamp = data[21]
identifiers = data[0:amountData]
values = data[10 : (10 + amountData)]
return {
"amountData": amountData,
"timestamp": timestamp,
"data": dict(zip(identifiers, values)),
}
def espnow_recv(result):
mac, peer, msg = result
data = bytes_to_data(msg)
try:
print(data["amountData"])
print(data["timestamp"])
print(data["data"])
print(str(binascii.hexlify(mac), "ascii"))
except Exception as error:
print(error)
from lib.espnow import Forte_ESPNOW
# data = DataTransferWiFi()
# data.connect("Z", "AbsoluteSandwich")
......@@ -41,15 +14,10 @@ def espnow_recv(result):
# "airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.4844531056779361 1661175680\nairSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.65192991869171,co=0.5141876544505826 1661175680\nairSensors,sensor_id=TLM0202 temperature=75.30007505999756,humidity=35.65192991869171,co=0.5141876544505826 1661175680"
# )
# data.disconnect()
#
espnow = Forte_ESPNOW()
w = WLAN()
ESPNOW.init()
p = ESPNOW.add_peer("58cf79043c84")
ESPNOW.on_recv(espnow_recv)
while True:
print("...")
rgbled(0x007f00)
sleep(5)
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment