-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cctweaker
committed
Jun 18, 2020
1 parent
14e6441
commit 9d31d6e
Showing
5 changed files
with
114 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
void init_espnow() | ||
{ | ||
if (esp_now_init() != 0) | ||
goto_sleep(); | ||
|
||
esp_now_set_kok(kok, 16); | ||
|
||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO); | ||
|
||
esp_now_add_peer(gmac, ESP_NOW_ROLE_COMBO, WIFI_CHANNEL, key, 16); | ||
esp_now_set_peer_key(gmac, key, 16); | ||
|
||
esp_now_register_send_cb(txcb); | ||
esp_now_register_recv_cb(rxcb); | ||
} | ||
|
||
void send_data() | ||
{ | ||
uint8_t byteArray[sizeof(tx)]; | ||
memcpy(byteArray, &tx, sizeof(tx)); | ||
esp_now_send(gmac, byteArray, sizeof(tx)); | ||
|
||
SENT = true; | ||
} | ||
|
||
void txcb(uint8_t *mac, uint8_t sendStatus) | ||
{ | ||
if (sendStatus == 0) | ||
ACK = true; | ||
} | ||
|
||
void rxcb(uint8_t *senderMac, uint8_t *incomingData, uint8_t len) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
void init_sensors() | ||
{ | ||
if (sensor.begin(2, 0)) | ||
{ | ||
SI = true; | ||
return; | ||
} | ||
|
||
if (BMESensor.begin()) | ||
{ | ||
BME = true; | ||
return; | ||
} | ||
|
||
// add DS18B20 init here | ||
|
||
if (!SI && !BME && !DS) | ||
goto_sleep(); | ||
} | ||
|
||
void prepare_data() | ||
{ | ||
|
||
float vin = (float)ESP.getVcc() / FACTOR; | ||
|
||
if (SI) | ||
{ | ||
si7021_env data = sensor.getHumidityAndTemperature(); | ||
|
||
float temp = data.celsiusHundredths / 100.0F; | ||
float hum = data.humidityBasisPoints / 100.0F; | ||
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))); | ||
|
||
sprintf(tx, "{\"t\":\"%s\",\"n\":\"%s\",\"ID\":\"%x\",\"v\":%d,\"tmp\":%.2f,\"hum\":%.2f,\"dew\":%.2f,\"vin\":%.2f}", TIP, NAME, ESP.getChipId(), VERSION, temp, hum, dew, vin); | ||
} | ||
|
||
if (BME) | ||
{ | ||
BMESensor.refresh(); | ||
// on the first reading, only after power down, BME280 reports erroneous values. | ||
// will need to discard the first reading in next version | ||
|
||
float temp = BMESensor.temperature; | ||
float hum = BMESensor.humidity; | ||
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\",\"n\":\"%s\",\"ID\":\"%x\",\"v\":%d,\"tmp\":%.2f,\"hum\":%.2f,\"dew\":%.2f,\"prs\":%.2f,\"prn\":%.2f,\"vin\":%.2f}", TIP, NAME, ESP.getChipId(), VERSION, temp, hum, dew, BMESensor.pressure / 100.0F, relativepressure, vin); | ||
} | ||
|
||
PREP = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters