Ciężkie nowego początki

User avatar
YoMan
Posts: 3522
Joined: Thu Apr 30, 2020 5:18 pm
Location: Częstochowa
Has thanked: 3 times
Been thanked: 3 times

Post

Próbuję się zmierzyć z nauczeniem czegoś więcej :) (nie miała baba kłopotu ....)
Przeglądam przykłady ale dochodzę do wniosku, że ciężko coś tam wydedukować - kody z różnych lat, każdy nieco inaczej pisany ... więc wziąłem do analizy kod, który na początku powinien mi się przydać:

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Please adjust GPIO to your board configuration
#define STATUS_LED_GPIO 2



#include <SuplaDevice.h>
#include <supla/network/esp_wifi.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/device/supla_ca_cert.h>
#include <supla/sensor/general_purpose_measurement.h>
#include <supla/sensor/virtual_hygromometer.h>

float data = 0;
int hygro = 0;

Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;

Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
Supla::EspWebServer suplaServer;

// HTML www component (they appear in sections according to creation
// sequence)
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Html::StatusLedParameters htmlStatusLed;

Supla::Sensor::GeneralPurposeMeasurement *gpm = nullptr;

void setup() {
  Serial.begin(115200);

  // Channels configuration
  // Channel #0 General Purpose Measurement
  // GPM class by deafult works as "virtual channel" (it accepts any value
  // via setValue(double) method.
  gpm = new Supla::Sensor::GeneralPurposeMeasurement();

  // Default channel config values are initialized only once. They can be
  // modified later, but they won't change corresponding used configurable
  // parameters.
  // Below lines are optional, just remove them if you don't want to set
  // them.
  gpm->setDefaultValueDivider(0);  // in 0.001 steps, 0 is ignored
  gpm->setDefaultValueMultiplier(0);  // in 0.001 steps, 0 is ignored
  gpm->setDefaultValueAdded(0);  // in 0.001 steps
  gpm->setDefaultUnitBeforeValue("before");
  gpm->setDefaultUnitAfterValue("after");
  gpm->setDefaultValuePrecision(3);  // 0..4 - number of decimal places

  // Set some initial value of measurement
  gpm->setValue(0);

  //
  hygro = new Supla::Sensor::VirtualHygroMeter();

  // configure defualt Supla CA certificate
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);

  SuplaDevice.begin();
}

void loop() {
  SuplaDevice.iterate();
  
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    data = Serial.read();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(data, DEC);
  }
  
  static uint32_t lastTime = 0;
  if (millis() - lastTime > 1000) {
    lastTime = millis();
    // set some new value on gpm:
    gpm->setValue(millis() / 1000.0);
  }
}
Nie pamiętam skąd bo go nie ma chyba w przykładach na supla-device, możliwe że z forum.
i wywala błąd kompilacji

Code: Select all

invalid conversion from 'Supla::Sensor::VirtualHygroMeter*' to 'int' [-fpermissive]
No więc:
1.co tu jest źle?
2. Czy może zacząć od czegoś innego jako pierwszy krok?
YoMan
________________________________________
Wziąłem udział w SOP2023 & SOP2024
[email protected]
Posts: 1586
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

YoMan wrote: Tue Aug 27, 2024 7:20 pm Próbuję się zmierzyć z nauczeniem czegoś więcej :) (nie miała baba kłopotu ....)
Przeglądam przykłady ale dochodzę do wniosku, że ciężko coś tam wydedukować - kody z różnych lat, każdy nieco inaczej pisany ... więc wziąłem do analizy kod, który na początku powinien mi się przydać:

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Please adjust GPIO to your board configuration
#define STATUS_LED_GPIO 2



#include <SuplaDevice.h>
#include <supla/network/esp_wifi.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/device/supla_ca_cert.h>
#include <supla/sensor/general_purpose_measurement.h>
#include <supla/sensor/virtual_hygromometer.h>

float data = 0;
int hygro = 0;

Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;

Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
Supla::EspWebServer suplaServer;

// HTML www component (they appear in sections according to creation
// sequence)
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Html::StatusLedParameters htmlStatusLed;

Supla::Sensor::GeneralPurposeMeasurement *gpm = nullptr;

void setup() {
  Serial.begin(115200);

  // Channels configuration
  // Channel #0 General Purpose Measurement
  // GPM class by deafult works as "virtual channel" (it accepts any value
  // via setValue(double) method.
  gpm = new Supla::Sensor::GeneralPurposeMeasurement();

  // Default channel config values are initialized only once. They can be
  // modified later, but they won't change corresponding used configurable
  // parameters.
  // Below lines are optional, just remove them if you don't want to set
  // them.
  gpm->setDefaultValueDivider(0);  // in 0.001 steps, 0 is ignored
  gpm->setDefaultValueMultiplier(0);  // in 0.001 steps, 0 is ignored
  gpm->setDefaultValueAdded(0);  // in 0.001 steps
  gpm->setDefaultUnitBeforeValue("before");
  gpm->setDefaultUnitAfterValue("after");
  gpm->setDefaultValuePrecision(3);  // 0..4 - number of decimal places

  // Set some initial value of measurement
  gpm->setValue(0);

  //
  hygro = new Supla::Sensor::VirtualHygroMeter();

  // configure defualt Supla CA certificate
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);

  SuplaDevice.begin();
}

void loop() {
  SuplaDevice.iterate();
  
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    data = Serial.read();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(data, DEC);
  }
  
  static uint32_t lastTime = 0;
  if (millis() - lastTime > 1000) {
    lastTime = millis();
    // set some new value on gpm:
    gpm->setValue(millis() / 1000.0);
  }
}
Nie pamiętam skąd bo go nie ma chyba w przykładach na supla-device, możliwe że z forum.
i wywala błąd kompilacji

Code: Select all

invalid conversion from 'Supla::Sensor::VirtualHygroMeter*' to 'int' [-fpermissive]
No więc:
1.co tu jest źle?
2. Czy może zacząć od czegoś innego jako pierwszy krok?
Zdefiniowałeś zmienna hydro jako int - liczbę a przypisujesz do niej obiekt 😉

Generalnie to podstawy języka trzeba zrozumieć
User avatar
YoMan
Posts: 3522
Joined: Thu Apr 30, 2020 5:18 pm
Location: Częstochowa
Has thanked: 3 times
Been thanked: 3 times

Post

[email protected] wrote: Tue Aug 27, 2024 7:44 pm
Zdefiniowałeś zmienna hydro jako int - liczbę a przypisujesz do niej obiekt 😉

Generalnie to podstawy języka trzeba zrozumieć
Podstawy .... właśnie próbuję ogarniać Arduino ... i zrozumieć o co chodzi z tym "obiektowym" ;)
Po secundo to nie ja ... skądś mam ten kod - sam bym go na pewno nie napisał - myślałem, że się coś z niego nauczę ale widać albo bzdura albo coś kiedyś próbowałem i zapomniałem o tym :)

W takim razie ma ktoś jakiś prosty kod (link) do wirtualnego sensora wilgotności, który zadziała i sie zaloguje w cloudzie? ... Najprostszy ... do nauki
YoMan
________________________________________
Wziąłem udział w SOP2023 & SOP2024
[email protected]
Posts: 1586
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

YoMan wrote: Tue Aug 27, 2024 7:54 pm
[email protected] wrote: Tue Aug 27, 2024 7:44 pm
Zdefiniowałeś zmienna hydro jako int - liczbę a przypisujesz do niej obiekt 😉

Generalnie to podstawy języka trzeba zrozumieć
Podstawy .... właśnie próbuję ogarniać Arduino ... i zrozumieć o co chodzi z tym "obiektowym" ;)
Po secundo to nie ja ... skądś mam ten kod - sam bym go na pewno nie napisał - myślałem, że się coś z niego nauczę ale widać albo bzdura albo coś kiedyś próbowałem i zapomniałem o tym :)

W takim razie ma ktoś jakiś prosty kod (link) do wirtualnego sensora wilgotności, który zadziała i sie zaloguje w cloudzie? ... Najprostszy ... do nauki
Z telefonu to trochę ciężko cytować :/

Zamień typ zmiennej hydro z int na ten z błędu Supla::Sensor::VirtualHygroMeter a z loopa usuń wszystko co stoi za IterateAlways
User avatar
YoMan
Posts: 3522
Joined: Thu Apr 30, 2020 5:18 pm
Location: Częstochowa
Has thanked: 3 times
Been thanked: 3 times

Post

[email protected] wrote: Tue Aug 27, 2024 8:03 pm Z telefonu to trochę ciężko cytować :/
to fakt :)
[email protected] wrote: Tue Aug 27, 2024 8:03 pm Zamień typ zmiennej hydro z int na ten z błędu Supla::Sensor::VirtualHygroMeter a z loopa usuń wszystko co stoi za IterateAlways
w błędzie nie widzę innego typu zmiennej
nie mam IterateAlways tylko SuplaDevice.iterate();

poczekam spokojnie .. może się znajdzie komputer w pobliżu :)

edit: coś drgnęło ;)
YoMan
________________________________________
Wziąłem udział w SOP2023 & SOP2024
[email protected]
Posts: 1586
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

YoMan wrote: Tue Aug 27, 2024 8:49 pm
[email protected] wrote: Tue Aug 27, 2024 8:03 pm Z telefonu to trochę ciężko cytować :/
to fakt :)
[email protected] wrote: Tue Aug 27, 2024 8:03 pm Zamień typ zmiennej hydro z int na ten z błędu Supla::Sensor::VirtualHygroMeter a z loopa usuń wszystko co stoi za IterateAlways
w błędzie nie widzę innego typu zmiennej
nie mam IterateAlways tylko SuplaDevice.iterate();

poczekam spokojnie .. może się znajdzie komputer w pobliżu :)

edit: coś drgnęło ;)
No racja, tam jest SuplaDevice.iterate() , tak to jest z telefonu odpisywać :P
Drgnęło, że masz dodany kanał ?:)
User avatar
YoMan
Posts: 3522
Joined: Thu Apr 30, 2020 5:18 pm
Location: Częstochowa
Has thanked: 3 times
Been thanked: 3 times

Post

[email protected] wrote: Wed Aug 28, 2024 4:59 am
YoMan wrote: Tue Aug 27, 2024 8:49 pm
[email protected] wrote: Tue Aug 27, 2024 8:03 pm Z telefonu to trochę ciężko cytować :/
to fakt :)
[email protected] wrote: Tue Aug 27, 2024 8:03 pm Zamień typ zmiennej hydro z int na ten z błędu Supla::Sensor::VirtualHygroMeter a z loopa usuń wszystko co stoi za IterateAlways
w błędzie nie widzę innego typu zmiennej
nie mam IterateAlways tylko SuplaDevice.iterate();

poczekam spokojnie .. może się znajdzie komputer w pobliżu :)

edit: coś drgnęło ;)
No racja, tam jest SuplaDevice.iterate() , tak to jest z telefonu odpisywać :P
Drgnęło, że masz dodany kanał ?:)
mam dodane nawet dwa kanały, ogarnąłem wstępne ustawienia nazw kanałów, nazwy urządzenia, befora/after, jednostki ... lecę dalej z dokształcaniem.
Ale .... mam dziwny problem: jeżeli wpiszę dane logowania ręcznie to się dodaje bez problemu do clouda ale przez apkę mówi, że nie widzi żadnego urządzenia do dodania chociaż rozsiewa swoją sieć (widzę ją na tel). Jakiś pomysł/wskazówka?
YoMan
________________________________________
Wziąłem udział w SOP2023 & SOP2024
User avatar
klew
Posts: 13911
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 136 times
Been thanked: 137 times

Post

Jak nazwałeś urządzenie?
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
Bania
Posts: 107
Joined: Wed Jul 24, 2024 5:03 pm
Location: Bielsko-Biała
Has thanked: 5 times
Been thanked: 5 times

Post

Moim zdaniem problem polega na tym, że urządzenie nie jest w trybie config. Zacznij od mojego minimalnego kodu i dodaj "swoje" zmienne. W tym kodzie zawarte jest, że przycisk na pinie 0, jest podłączony z uruchomieniem trybu config.

Code: Select all

#include <SuplaDevice.h>
#include <supla/control/button.h>
#include <supla/device/status_led.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/network/esp_web_server.h>
#include <supla/network/esp_wifi.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/storage/littlefs_config.h>

Supla::Device::StatusLed statusLed(13, true);
Supla::ESPWifi wifi;
Supla::EspWebServer suplaServer;
Supla::LittleFsConfig configSupla;

void setup() 
{
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;

  auto suplaPrzyciskCfg = new Supla::Control::Button(0, true, true);
  suplaPrzyciskCfg->configureAsConfigButton(&SuplaDevice);

  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);

  SuplaDevice.begin();
}

void loop()
{
  SuplaDevice.iterate();
}
https://github.com/anarhbania/Supla
User avatar
YoMan
Posts: 3522
Joined: Thu Apr 30, 2020 5:18 pm
Location: Częstochowa
Has thanked: 3 times
Been thanked: 3 times

Post

Właśnie mnie Łukasz oświecił. @klew dobry trop ... domyślny jesteś
YoMan
________________________________________
Wziąłem udział w SOP2023 & SOP2024

Return to “supla-dev”