Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cctweaker committed Aug 23, 2021
1 parent 1ecf3bd commit a98f52a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
9 changes: 6 additions & 3 deletions ESPsensor/ESP-Now.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
void rxcb(uint8_t *senderMac, uint8_t *incomingData, uint8_t len)
{
ACK = true;
}
23 changes: 18 additions & 5 deletions ESPsensor/ESPsensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C"
#include <user_interface.h>
}
#include <Wire.h>
#include "private.h"
#include "example_private.h"

//

Expand All @@ -24,6 +24,12 @@ BME280<> BMESensor;

//

#ifdef SENSOR_DS1820
// todo
#endif

//

void initVariant()
{
WiFi.mode(WIFI_AP);
Expand Down Expand Up @@ -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);
}
void goto_sleep()
{
ESP.deepSleepInstant(SLEEP, RF_NO_CAL);
}
29 changes: 17 additions & 12 deletions ESPsensor/example_private.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/////////////////////////////////////////////////
// edit this file before building
// change the values BELOW this text to your liking
/////////////////////////////////////////////////

//

/////////////////////////////////////////////////
// Firmware specific
/////////////////////////////////////////////////
Expand All @@ -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
Expand All @@ -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
/////////////////////////////////////////////////
Expand Down Expand Up @@ -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};
/////////////////////////////////////////////////

//
Expand Down Expand Up @@ -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
/////////////////////////////////////////////////
Expand All @@ -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)
//
Expand Down
12 changes: 9 additions & 3 deletions ESPsensor/sensors.ino
Original file line number Diff line number Diff line change
@@ -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
}

//
Expand Down Expand Up @@ -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());
}

Expand Down
6 changes: 2 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit a98f52a

Please sign in to comment.