Zakładam ten temat z nadzieją, że znajdą się dobre duszyczki chcące trochę potłumaczyć użytkownikom początkującym jak ja, by mogli sobie zespolić oprogramowanie, które łączy moduły ESP8266 z serwerem Supla z własnym kodem Arduino. Dzięki uprzejmości kolegi #nebraska dostałem kod na kilka przekaźników, przycisków, czujnik BME, krańcówki itp. za co mu jeszcze raz z góry dziękuję. To otwiera spore jeśli nie ogromne pole do nauki, ale mam szereg pytań jako zielony w temacie. I może właśnie Wy, bardziej ogarnięci macie odrobinę cierpliwości by to wyjaśnić. Poniżej otrzymany kod.
Code: Select all
#include <Arduino.h>
#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/network/esp_wifi.h>
#include <ESP8266WiFi.h>
#include <supla/uptime.h>
#include <supla/sensor/therm_hygro_meter.h>
#include <supla/sensor/hygro_meter.h>
#include <supla/storage/eeprom.h>
#include <supla/sensor/bme280.h>
#include <supla/sensor/binary.h>
#define STORAGE_OFFSET 100
Supla::Eeprom eeprom(STORAGE_OFFSET);
Supla::Uptime mojeUptime;
const char* host = "svrX.supla.org";
const char* ssid = "XXXXXXXX";
const char* pass = "XXXXXXXX";
Supla::ESPWifi wifi(ssid, pass);
unsigned long times;
//----------------------------------------------------------
//globalne uruchomienie kabnalow SUPLA
auto r1 = new Supla::Control::Relay(12, true); // Jesli chcemy zmienic stan przekażnika załączenie. Stan Niski- false, Stan Wysoki true.
auto r2 = new Supla::Control::Relay(13, true); // Jesli chcemy zmienic stan przekażnika załączenie. Stan Niski- false, Stan Wysoki true.
auto r3 = new Supla::Control::Relay(4, true); // Jesli chcemy zmienic stan przekażnika załączenie. Stan Niski- false, Stan Wysoki true.
auto r4 = new Supla::Control::Relay(5, true); // Jesli chcemy zmienic stan przekażnika załączenie. Stan Niski- false, Stan Wysoki true.
//------------------- Deklaracja czujnika BME280 Supla --------------------------------------------------------------------------------------------------------------
class BME280 : public Supla::Sensor::ThermHygroPressMeter {
public:
BME280(int8_t address = 0x76, float altitude = NAN) : address(address), sensorStatus(false), altitude(altitude) {
}
double getTemp() {
float value = TEMPERATURE_NOT_AVAILABLE;
bool retryDone = false;
do {
if (!sensorStatus || isnan(value)) {
sensorStatus = bme.begin(address);
retryDone = true;
}
value = TEMPERATURE_NOT_AVAILABLE;
if (sensorStatus) {
value = bme.readTemperature();
}
} while (isnan(value) && !retryDone);
return value;
}
double getHumi() {
float value = HUMIDITY_NOT_AVAILABLE;
bool retryDone = false;
do {
if (!sensorStatus || isnan(value)) {
sensorStatus = bme.begin(address);
retryDone = true;
}
value = HUMIDITY_NOT_AVAILABLE;
if (sensorStatus) {
value = bme.readHumidity();
}
} while (isnan(value) && !retryDone);
return value;
}
double getPressure() {
float value = PRESSURE_NOT_AVAILABLE;
bool retryDone = false;
do {
if (!sensorStatus || isnan(value)) {
sensorStatus = bme.begin(address);
retryDone = true;
}
value = PRESSURE_NOT_AVAILABLE;
if (sensorStatus) {
value = bme.readPressure() / 100.0;
}
} while (isnan(value) && !retryDone);
if (!isnan(altitude)) {
value = bme.seaLevelForAltitude(altitude, value);
}
return value;
}
void onInit() {
sensorStatus = bme.begin(address);
pressureChannel.setNewValue(getPressure());
channel.setNewValue(getTemp(), getHumi());
}
void setAltitude(float newAltitude) {
altitude = newAltitude;
}
protected:
int8_t address;
bool sensorStatus;
float altitude;
Adafruit_BME280 bme; // I2C
};
BME280*bm;
void setup() {
Serial.begin(115200);
// 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] = { };
bm = new BME280; // Deklaracja BME280 Supla.
new Supla::Sensor::Binary(14, true); //kontaktron bramy wjazdowej -brama zamknięta
// false-zalaczenie sensora nastepuje podczas zwarcia (3v3 poprzez 4,7k + D1 ) z GND lub (5V poprzez 10k + D1 ) z GND
SuplaDevice.begin(GUID, // Global Unique Identifier
host, // SUPLA server address
"YOUR EMAIL", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
void loop() {
SuplaDevice.iterate(); // Jednorazowe Wywołanie Supli
}1.
Code: Select all
Supla::Uptime mojeUptime;2.
Code: Select all
if (!sensorStatus || isnan(value))3.
Code: Select all
char GUID[SUPLA_GUID_SIZE] = {};4.
Code: Select all
void loop()
{
SuplaDevice.iterate(); // Jednorazowe Wywołanie Supli
}5.
Code: Select all
new Supla::Sensor::Binary(14, true); // kontaktron bramy wjazdowejJeżeli w poniższym zapisie mam kontaktron na pinie 14 i informacja ta jest przekazywana do Supli to czy mogę równorzędnie napisać w pętli głównej
Code: Select all
bool krancowka = (digitalRead, 14);6.
Code: Select all
auto r1 = new Supla::Control::Relay(12, false);To dopiero początek pytań.
