[PODSTAWY] Pomoc przy analizie programu od podstaw - dla zielonych

matrix0606
Posts: 496
Joined: Tue Nov 08, 2022 9:05 pm

Post

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.
Przepraszam, to nie ten kod. Lepiej to wkleję, będzie łatwiej.

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
}
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.
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.
Vivo V21 5G 8G RAM + 4G SWAP - Funtouch OS 12 Global
MOBO - MSI B350 Tomahawk || GPU - XFX Radeon RX 6600 Speedster
CPU - Ryzen5 1400 3,2G || PSU - SPC Vero | L2 500W 80 Plus Bronze
RAM - HyperX 2x8GB 3200MHz CL16 Predator RGB
matrix0606
Posts: 496
Joined: Tue Nov 08, 2022 9:05 pm

Post

Na obecną chwilę, taki goły kod zupełnie bez niczego, kompiluje się poprawnie. Pytanie, co ja mogę dalej z tym zrobić? I przede wszystkim to jest na ESP8266 a jak mam zaincludować ESP32 WROOM?

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>
#include <WebServer.h>
#include <LittleFS.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.

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] = {};

  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
}
Vivo V21 5G 8G RAM + 4G SWAP - Funtouch OS 12 Global
MOBO - MSI B350 Tomahawk || GPU - XFX Radeon RX 6600 Speedster
CPU - Ryzen5 1400 3,2G || PSU - SPC Vero | L2 500W 80 Plus Bronze
RAM - HyperX 2x8GB 3200MHz CL16 Predator RGB
nebraska
Posts: 204
Joined: Thu Dec 08, 2022 3:00 pm
Been thanked: 1 time

Post

matrix0606 wrote: Thu May 18, 2023 8:30 pm Na obecną chwilę, taki goły kod zupełnie bez niczego, kompiluje się poprawnie. Pytanie, co ja mogę dalej z tym zrobić? I przede wszystkim to jest na ESP8266 a jak mam zaincludować ESP32 WROOM?

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>
#include <WebServer.h>
#include <LittleFS.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.

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] = {};

  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
}
W tym kodzie masz przykład 4 przekaźników i czujnika otwarcia/zamkniecia. Tam gdzie masz GUID i AUTHKEY musisz kliknac w linki w kodzie i wygenerować GUID i AUTHKEY otworzy się strona skopiować i wkleić między klamrami { }
Na górze wpisać swoje wifi hasło,login,serwer, np svr34.supla.org
Na dole gdzie pole "EMAIL" podać swojego emaila.
Kod powinien się skompletować na esp32 i esp8266. Nie trzeba includowac to już jest w bibliotece Supli.
Tylko daj Board manager dla Esp32 2.0.3 lub wyższy.

Return to “Pomoc”