Chciałbym zapytać czy ten sketch który napisałem jest poprawny, czy można go jakoś jeszcze uprościć, chciałbym dodać jeszcze odczyt BME, gdzieś się pogubiłem w kodzie i nie wiem dokładnie jak to zrobić. Odczyt w jednym kanale Temperatura i Wilgotność, a w drugim temp, wilg, ciśnienie (BME), wszystkie dane oraz zmienne sobie przesyłam/prześlę poprzez NRF24RL01
#include <SuplaDevice.h>
#include <Arduino.h>
#include <SPI.h>
//#include <Wire.h>
//#include <Adafruit_GFX.h>
//#include <Adafruit_SSD1306.h>
#include <nRF24L01.h>
#include "RF24.h"
#include <supla/sensor/DS18B20.h>
#include <supla/sensor/Thermometer.h>
#include <supla/sensor/virtual_therm_hygro_meter.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/roller_shutter.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
#include <supla/control/action_trigger.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/network/html/security_certificate.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/events.h>
#include <supla/io.h>
#include <supla/sensor/virtual_thermometer.h>
#include <supla/sensor/therm_hygro_press_meter.h>
//float temp;
float dane[2];
//const uint64_t pipe = 0xF0F0F0F0E1LL;
//Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1);
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {******};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {*****};
#define WIFI_NETWORK "****"
#define WIFI_PASSWORD "******"
#define WIFI_TIMEOUT_MS 20000
Supla::ESPWifi wifi(WIFI_NETWORK, WIFI_PASSWORD);
Supla::Sensor::VirtualThermHygroMeter *therm1 = nullptr;
Supla::Sensor::VirtualThermometer *therm2 = nullptr;
RF24 radio(4,15); // CE, CSN
const uint64_t pipe = 0x00FF;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_HIGH);
radio.openReadingPipe(1, pipe);
radio.startListening();
//display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//display.clearDisplay();
//display.setTextColor(WHITE);
therm1 = new Supla::Sensor::VirtualThermHygroMeter;
therm2 = new Supla::Sensor::VirtualThermHygroMeter;
SuplaDevice.begin(GUID, "svrXX.supla.org", "[email protected]", AUTHKEY);
}
void loop()
{
static uint64_t lastTempTimestamp = 0;
if (!lastTempTimestamp || millis() - lastTempTimestamp > 10000)
{
lastTempTimestamp = millis();
odczyt();
double termometr1 = dane[0];
double wilgotnosc1 = dane[1];
therm1->setTemp(termometr1); // to działa
therm1->setHumi(wilgotnosc1); // to też
//therm2->setPressure(random(990, 1100));
}
SuplaDevice.iterate();
}
void odczyt()
{
if (radio.available())
{
bool done = false;
radio.read(&dane, sizeof(dane));
}
}
