From a98f52a5f391ba67b57274e91a4c1d630136850f Mon Sep 17 00:00:00 2001 From: cctweaker <> Date: Mon, 23 Aug 2021 17:53:07 +0300 Subject: [PATCH] minor changes --- ESPsensor/ESP-Now.ino | 9 ++++++--- ESPsensor/ESPsensor.ino | 23 ++++++++++++++++++----- ESPsensor/example_private.h | 29 +++++++++++++++++------------ ESPsensor/sensors.ino | 12 +++++++++--- platformio.ini | 6 ++---- 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/ESPsensor/ESP-Now.ino b/ESPsensor/ESP-Now.ino index 9de9e8e..e707286 100644 --- a/ESPsensor/ESP-Now.ino +++ b/ESPsensor/ESP-Now.ino @@ -29,10 +29,13 @@ void send_data() void txcb(uint8_t *mac, uint8_t sendStatus) { - if (sendStatus == 0) - ACK = true; + // if (sendStatus == 0) + ACK = true; } // -void rxcb(uint8_t *senderMac, uint8_t *incomingData, uint8_t len) {} \ No newline at end of file +void rxcb(uint8_t *senderMac, uint8_t *incomingData, uint8_t len) +{ + ACK = true; +} diff --git a/ESPsensor/ESPsensor.ino b/ESPsensor/ESPsensor.ino index b0d52bc..cafb043 100644 --- a/ESPsensor/ESPsensor.ino +++ b/ESPsensor/ESPsensor.ino @@ -6,7 +6,7 @@ extern "C" #include } #include -#include "private.h" +#include "example_private.h" // @@ -24,6 +24,12 @@ BME280<> BMESensor; // +#ifdef SENSOR_DS1820 +// todo +#endif + +// + void initVariant() { WiFi.mode(WIFI_AP); @@ -54,8 +60,15 @@ void loop() send_data(); if (ACK) - ESP.deepSleepInstant(SLEEP, RF_NO_CAL); + goto_sleep(); + + if (millis() > 600) // sleep if data not yet sent/acknowledged + goto_sleep(); +} + +// - if (millis() > 1000) // sleep if data not sent in 1 second - ESP.deepSleepInstant(SLEEP, RF_NO_CAL); -} \ No newline at end of file +void goto_sleep() +{ + ESP.deepSleepInstant(SLEEP, RF_NO_CAL); +} diff --git a/ESPsensor/example_private.h b/ESPsensor/example_private.h index a2af159..054be9c 100644 --- a/ESPsensor/example_private.h +++ b/ESPsensor/example_private.h @@ -1,3 +1,10 @@ +///////////////////////////////////////////////// +// edit this file before building +// change the values BELOW this text to your liking +///////////////////////////////////////////////// + +// + ///////////////////////////////////////////////// // Firmware specific ///////////////////////////////////////////////// @@ -6,12 +13,6 @@ // -// -// rename this file to private.h before building -// and change the values BELOW this text to your liking -// - -// ///////////////////////////////////////////////// // select sensor type @@ -20,10 +21,13 @@ // it is better to have the firmware expect // the correct sensor // uncomment one of the below options -#define SENSOR_SI7021 -// #define SENSOR_BME280 +// #define SENSOR_SI7021 +#define SENSOR_BME280 +// #define SENSOR_DS1820 ///////////////////////////////////////////////// +// + ///////////////////////////////////////////////// // private MAC addresses ///////////////////////////////////////////////// @@ -59,7 +63,7 @@ uint8_t mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE}; // sensors // pick 16 random numbers to use as device key encoding key uint8_t kok[16] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF}; // pick 16 random numbers to use as device key -uint8_t key[16] = {0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED}; +uint8_t key[16] = {0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD}; ///////////////////////////////////////////////// // @@ -93,11 +97,12 @@ uint8_t key[16] = {0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED, 0 // sleep time (message rate) ///////////////////////////////////////////////// // min sec msec usec -#define SLEEP 10 * 60 * 1000 * 1000 // 10 minutes +// #define SLEEP 10 * 60 * 1000 * 1000 // 10 minutes // #define SLEEP 5 * 60 * 1000 * 1000 // 5 minutes -// #define SLEEP 2 * 60 * 1000 * 1000 // 2 minutes +#define SLEEP 2 * 60 * 1000 * 1000 // 2 minutes // #define SLEEP 1 * 60 * 1000 * 1000 // 1 minute // #define SLEEP 1 * 30 * 1000 * 1000 // 30 seconds +// #define SLEEP 1 * 10 * 1000 * 1000 // 10 seconds // estimate your power consumption here: // https://3dstar.ro/calculator-consum-baterii-acumulatori ///////////////////////////////////////////////// @@ -122,7 +127,7 @@ char tx[128]; // BME280 ///////////////////////////////////////////////// // input your correct sensor altitude in meters -#define MYALTITUDE 100 // altitude in meters +#define MYALTITUDE 50 // altitude in meters // this value is needed for correct normalized // pressure value (USA & Canada) // diff --git a/ESPsensor/sensors.ino b/ESPsensor/sensors.ino index fd5193d..72c0fb6 100644 --- a/ESPsensor/sensors.ino +++ b/ESPsensor/sensors.ino @@ -1,17 +1,22 @@ void init_sensors() { #ifdef SENSOR_SI7021 + // if (sensor.begin(0, 2)) // testboard if (sensor.begin(2, 0)) // PCB - // if (sensor.begin(0, 2)) // perfboard SI = true; #endif #ifdef SENSOR_BME280 + // Wire.begin(0, 2); // testboard + Wire.begin(2, 0); // PCB if (BMESensor.begin()) BME = true; #endif - // add DS18B20 init here +#ifdef SENSOR_DS1820 + // todo + DS = true; +#endif } // @@ -43,12 +48,13 @@ void prepare_data() float dew = 243.04 * (log(hum / 100.0) + ((17.625 * temp) / (243.04 + temp))) / (17.625 - log(hum / 100.0) - ((17.625 * temp) / (243.04 + temp))); float relativepressure = BMESensor.seaLevelForAltitude(MYALTITUDE) / 100.0F; - sprintf(tx, "{\"t\":\"%s\",\"v\":%.2f,\"ID\":\"%x\",\"vcc\":%d,\"tmp\":%.2f,\"hum\":%.2f,\"dew\":%.2f,\"prs\":%.2f,\"prn\":%.2f}", FWN, VERSION, ESP.getChipId(), ESP.getVcc(), temp, hum, dew, BMESensor.pressure / 100.0F, relativepressure); + sprintf(tx, "{\"t\":\"%s\",\"v\":%.2f,\"ID\":\"%06x\",\"vcc\":%d,\"tmp\":%.2f,\"hum\":%.2f,\"dew\":%.2f,\"prs\":%.2f,\"prn\":%.2f}", FWN, VERSION, ESP.getChipId(), ESP.getVcc(), temp, hum, dew, BMESensor.pressure / 100.0F, relativepressure); } #endif if (!SI && !BME && !DS) { + // no sensor detected, send some data! sprintf(tx, "{\"t\":\"%s\",\"v\":%.2f,\"ID\":\"%x\",\"vcc\":%d}", FWN, VERSION, ESP.getChipId(), ESP.getVcc()); } diff --git a/platformio.ini b/platformio.ini index db58bc2..d488d75 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,15 +19,13 @@ framework = arduino board = esp01_1m board_build.flash_mode = dout board_build.ldscript = eagle.flash.1m.ld -platform = espressif8266 +platform = espressif8266@2.5.1 ;locked for ESP-Now! board_build.f_cpu = 80000000L monitor_speed = 115200 upload_speed = 921600 upload_resetmethod = nodemcu lib_deps = 536 ; Si7021@06fadfb576 1554 ; BME280_Light@600667f3a6 -build_flags = -DVERSION=2.01 +build_flags = -DVERSION=2.02 extra_scripts = pre:tools\firmware_name.py post:tools\copy_compress.py - - \ No newline at end of file