mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-08 13:10:29 +00:00
Update BME280_8266.ino
fixed it
This commit is contained in:
parent
b9272031d1
commit
e6a4f1fdfd
@ -4,19 +4,22 @@
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a two-byte identifier along with a one-byte sensor type
|
||||
// !!Untested on actual hardware!!
|
||||
//
|
||||
|
||||
#define TEMP_ID 10 //Unique ID (0 - 1023) for each data reading
|
||||
#define HUM_ID 11
|
||||
#define PRES_ID 2
|
||||
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define SLEEPYTIME 10 //Time to sleep in seconds
|
||||
#define TEMP_ID 0 //Unique ID (0 - 1023) for each data reading
|
||||
#define HUM_ID 1
|
||||
#define PRESS_ID 2
|
||||
#define SLEEPYTIME 60 //Time to sleep in seconds
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
Adafruit_BME280 bmp; //0x77
|
||||
|
||||
Adafruit_BME280 bme; //0x76
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, TERM_MAC};
|
||||
int wait_time = 0;
|
||||
|
||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
Serial.print("Last Packet Send Status: ");
|
||||
@ -43,22 +46,54 @@ typedef struct DataPacket {
|
||||
} DataPacket;
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin();
|
||||
uint8_t addr = 0x76;
|
||||
while (!bmp.begin()) {
|
||||
while (!bme.begin(0x76)) {
|
||||
delay(10);
|
||||
}
|
||||
Serial.println("bme INIT");
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
// Register peer
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
if (millis() > wait_time) {
|
||||
wait_time = wait_time + SLEEPYTIME * 1000;
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
void loadData() {
|
||||
float bme_temp = bmp.readTemperature();
|
||||
float bme_pressure = (bmp.readPressure() / 100.0F);
|
||||
//float bme_altitude = bmp.readAltitude(1013.25);
|
||||
float bme_humidity = bmp.readHumidity();
|
||||
float bme_temp = bme.readTemperature();
|
||||
float bme_pressure = (bme.readPressure() / 100.0F);
|
||||
//float bme_altitude = bme.readAltitude(1013.25);
|
||||
float bme_humidity = bme.readHumidity();
|
||||
Serial.println(bme_temp);
|
||||
DataReading Temp;
|
||||
Temp.d = bme_temp;
|
||||
Temp.id = TEMP_ID;
|
||||
Temp.t = 1;
|
||||
|
||||
DataReading Hum;
|
||||
Hum.d = bme_humidity;
|
||||
Hum.id = HUM_ID;
|
||||
Hum.t = 2;
|
||||
|
||||
DataReading Pres;
|
||||
Pres.d = bme_pressure;
|
||||
Pres.id = PRES_ID;
|
||||
Pres.t = 3;
|
||||
|
||||
DataPacket thePacket;
|
||||
thePacket.packet[0] = Temp;
|
||||
thePacket.packet[1] = Hum;
|
||||
//thePacket.packet[2] = Pres;
|
||||
thePacket.l = 2;
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &thePacket, sizeof(thePacket));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user