Przepraszam, to nie ten kod. Lepiej to wkleję, będzie łatwiej.klew wrote: Thu May 18, 2023 8:13 pm Kod w tamtym linku nie ma niczego zwiazanego z bme, więc ciężko coś podpowiedzieć.
Błędy, które masz na ekranie są dość jasne - używasz nazwy "bme", która nie została wcześniej nigdzie zdefiniowana.
Code: Select all
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/network/esp_wifi.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);
const char *host = "svrxx.supla.org";
const char *ssid = "xxxx";
const char *pass = "xxxx";
Supla::ESPWifi wifi(ssid, pass);
unsigned long times;
//----------------------------------------------------------
// globalne uruchomienie kanałów 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
"EMAIL", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
void loop()
{
SuplaDevice.iterate(); // Wywołanie Supli
}Nienawidzę gołego arduino IDE jest ohydne, nie ma podpowiedzi składni, nie ma jej kolorowania, a z VSC ogólnie nie mam problemów. Napisałem już sporo programów na arduino nano i nie było kłopotów.klew wrote: Thu May 18, 2023 8:13 pm Ogólnie nie wiem czy dla osoby początkującej, samo "gołe" Arduino IDE nie jest prostsze.
