esp_garden git · master
Distributed ESP sensor and actuator system (garden)
C++ 70.7% Markdown 18% C 10.7%git clone https://git.christianimmanuel.de/embedded/esp_garden.gitwget https://git.christianimmanuel.de/embedded/esp_garden/archive/esp_garden.tar.gzUpdate pass reference instead of id
client_sensor/ClientSensor.cpp | 9 ++------- client_sensor/ClientSensor.h | 4 ++-- client_sensor/client_sensor.ino | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/client_sensor/ClientSensor.cpp b/client_sensor/ClientSensor.cpp index 4d2f953..c0982ee 100644 --- a/client_sensor/ClientSensor.cpp +++ b/client_sensor/ClientSensor.cpp @@ -373,9 +373,7 @@ uint16_t get_CurrentMinutes() { // ---------------------------------------------------------------------------- -bool is_TimeToReadSensor(size_t config_id) { - SensorConfig_s& p = sensor_configs[config_id]; - +bool is_TimeToReadSensor(SensorConfig_s& p) { DBG_PRINTF("check is_TimeToReadSensor: %s\n", p.sensor_name); if (!p.is_active) { @@ -693,12 +691,9 @@ void get_AllSensorConfigs() { // ---------------------------------------------------------------------------- -void send_DataToPeer(size_t config_id, uint32_t value) { +void send_DataToPeer(SensorConfig_s& p, uint32_t value) { char message[64]; - - SensorConfig_s& p = sensor_configs[config_id]; - DBG_PRINTF("send_DataToPeer: %s\n", p.sensor_name); snprintf(message, sizeof(message), "%s:%u:%lld", p.sensor_name, value, p.last_sensor_read); diff --git a/client_sensor/ClientSensor.h b/client_sensor/ClientSensor.h index a874281..40a212e 100644 --- a/client_sensor/ClientSensor.h +++ b/client_sensor/ClientSensor.h @@ -65,8 +65,8 @@ void process_PendingSensorConfigs(); // Send Data to peers // ---------------------------------------------------------------------------- -bool is_TimeToReadSensor(size_t config_id); -void send_DataToPeer(size_t config_id, uint32_t value); +bool is_TimeToReadSensor(SensorConfig_s& p); +void send_DataToPeer(SensorConfig_s& p, uint32_t value); void send_NextSensorReadToPeer(const uint8_t* mac, int64_t unix_time); diff --git a/client_sensor/client_sensor.ino b/client_sensor/client_sensor.ino index ab0ad28..8c82f27 100644 --- a/client_sensor/client_sensor.ino +++ b/client_sensor/client_sensor.ino @@ -46,7 +46,7 @@ void loop() { SensorConfig_s &peer = sensor_configs[config_id]; DBG_PRINTF("LOOP checking config: %s\n", peer.sensor_name); print_SensorConfig(peer); - if ( is_TimeToReadSensor(config_id) ) { + if ( is_TimeToReadSensor(peer) ) { DBG_PRINTLN("ITS TIME FOR THIS SENSOR!"); /* * read sensor value @@ -61,7 +61,7 @@ void loop() { get_NextSensorReadFor(sensor_configs[config_id].sensor_name); // send to server and configured peer (e.g. pump) - send_DataToPeer(config_id, value_to_send); + send_DataToPeer(peer, value_to_send); fake_value_to_send++; } print_SensorConfig(peer);