Jak przesłać dane napięcia z ESP8266 na SUPLA

Mix
Posts: 6
Joined: Mon Feb 04, 2019 9:43 am

Post

Witam,

Mam ładowarkę akumulatorów z którą komunikuję się po UART i dostaję z niej stringa z wszystkimi parametrami.
Z stringa powyciągam co potrzebuję do zmiennych, ale nie mam pomysłu jak przesłać zmienne do supli.
Znalazłem podobny wątek:

Potrzebuję 4 zmiennych
- Napięcie PV
- Prąd PV
- Napięcie akumulatora
- Prąd akumulatora


viewtopic.php?t=7433

Ale nie wiem jak przerobić kod żeby wysyłał dane do supli.

Kod z tamtego przykładu:


Code: Select all

#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/sensor/DS18B20.h>
#include <supla/sensor/thermometer.h>
#include <supla/control/relay.h>
#include <supla/sensor/binary.h>

/*
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
*/

//=========== DOPISANE =====================================
const int analogInPin = A0;  // ESP8266 Analog Pin ADC0 = A0

// Przewód danych jest podłączony do portu 2 na Arduino
#define ONE_WIRE 2
#define ONE_WIRE_2 4       //(D2)-(4) // (D5) DOPISANE Dodatkowy DS(3)

// Setup Supla connection
const char* ssid     = "*************";
const char* password = "************";

Supla::ESPWifi wifi(ssid, password);

class AnalogValue : public Supla::Sensor::Thermometer {
  public:
    AnalogValue(int pin) : pin(pin) {
    }
    
    void onInit() {
      pinMode(pin, INPUT); 
      channel.setNewValue(getValue());
    }

    double getValue() {
      return analogRead(pin);
    }

  protected:
    int pin;

};


/*
 *
WiFiClient client;
const char* host = "supla";
const char* update_path = "/supla";
const char* update_username = "admin";
const char* update_password = "supla";

ESP8266WebServer httpServer(81);
ESP8266HTTPUpdateServer httpUpdater;

*/
//=======================================================================================
void setup() {
  Serial.begin(115200);

  delay(10);

  wifi_station_set_hostname("Supla-PIEC");  //nazwa w sieci lokalnej
  WiFi.softAPdisconnect(true);             // wyłączenie rozgłaszania sieci ESP
  
  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {0xD1,0xE0,0xF5,0xB0,0x02,0x6E,0x1B,0x8F,0xF8,0xAC,0x6B,0x23,0xFD,0xB7,0x5E,0x2B};
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0x11,0xB7,0x0B,0xE0,0x53,0x92,0x63,0xC2,0x13,0x50,0xC2,0x84,0x98,0x38,0x42,0x6C};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  new Supla::Sensor::DS18B20(ONE_WIRE);
  new Supla::Sensor::DS18B20(ONE_WIRE_2);

  new Supla::Control::Relay(15, false); 

  new Supla::Sensor::Binary(5, true);
  new Supla::Sensor::Binary(14, true);
  new Supla::Sensor::Binary(12, true);
  new Supla::Sensor::Binary(13, true);
  
  new AnalogValue(analogInPin);

//***************************************************************************
  SuplaDevice.setName("supla_PIEC");
  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    "svr.supla.org",      // SUPLA server address 
                    "[email protected]",     // email
                    AUTHKEY);   

//***************************************************************************
/*
  Serial.println();
  Serial.println("Uruchamianie serwera aktualizacji...");
  WiFi.mode(WIFI_STA);

  MDNS.begin(host);
  httpUpdater.setup(&httpServer, update_path, update_username, update_password);
  httpServer.begin();
  MDNS.addService("http", "tcp", 81);
  Serial.printf("HTTPUpdateServer ready! Open http://%s.local%s in your browser and login with username '%s' and password '%s'\n", host, update_path, update_username, update_password);
 */
} //KONIEC-> setup()
//===============================================================================

void loop() {

  SuplaDevice.iterate();
  //httpServer.handleClient();
}
Mix
Posts: 6
Joined: Mon Feb 04, 2019 9:43 am

Post

Tutaj podobny temat:
Przesyłanie po UDP/RS232 wartości liczbowych.

viewtopic.php?t=9022&start=10

I o coś takiego mi chodzi, nie wiem jak wysłać jakąkolwiek daną po aktualizacji bibliotek arduino.
Gdyby ktoś podpowiedział jak wysłać dowolną zmienną, z tego co rozumiem to naprościej będzie jako termometr ?
Ale jak ją tam wrzucić??
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Mix wrote: Thu Mar 24, 2022 1:43 pm Potrzebuję 4 zmiennych
- Napięcie PV
- Prąd PV
- Napięcie akumulatora
- Prąd akumulatora
Jak chcesz te dane wyświetlić w Supli? Ja bym sugerował licznik prądu, który by pokazywał napięie i prąd. Jednak liczniki na głównym ekranie z listą kanałów pokazują zużycie energii w kWh, więc jeśli w danych masz tylko prąd i napięcie, to na głównym ekranie będziesz cały czas widział "0 kWh" i dopiero po wejściu w szczegóły zobaczysz wartości prądu i napięcia. Także tutaj byłyby dwa osobne kanały - jeden dla PV, drugi dla akumulatora.

Alternatywnie jako obejćie problemu braku "kanału pomiarowego ogólnego przeznaczenia", wiele osób korzysta w tym celu z kanału termometru. Wtedy będziesz miał osobne 4 kanały i każdy pokaże jednostkę "stopień", ale w podpisie możesz sobie ustawić co to jest oraz podmienić ikonę.

Daj znać, jak byś chciał to mieć prezentowane.
Najlepsze suple dla Twojego domu :mrgreen:
Mix
Posts: 6
Joined: Mon Feb 04, 2019 9:43 am

Post

Dięki za zainteresowanie tematem.

Z tego co widzę to ładowarka udostępnia funkcję licznika energii.
To co chciałbym wysyłać do SUPLI to te kilka wartości o których napisałem powyżej.
Może być w formie termometru, uczę się programować i wydaje mi się że tak będzie dla mnie bardziej prosto.


Poniżej opis tego co dostaję od ładowarki solarnej wraz z opisem poszczególnych wartości

Code: Select all


(014.4 00.0 10.20 00.1 00.0 00000 00000 00000 00000 21.08.03 1 00 023 0⸮A
(012.9 00.0 10.10 00.1 00.0 00000 00000 00000 00000 21.08.03 1 00 023 0⸮B
(026.6 00.0 09.90 00.0 00.0 00000 00000 00000 00000 21.08.03 0 03 023 0u#
(026.6 00.0 09.90 00.0 00.0 00000 00000 00000 00000 21.08.03 0 00 023 0⸮⸮
(017.5 00.0 10.20 00.1 00.0 00000 00000 00000 00000 21.08.03 1 00 023 0⸮⸮


QRTV<cr>: Device general status parameters inquiry
Computer: QRTV<cr>
Device: (BBB.B CC.C DD.DD EE.E FF.F GGGG HHHH IIII JJJJ KK.KK.KK
L MM NNN O<CRC><cr>
Data Description Notes
(  - Start byte
BBB.B - PV voltage B is an Integer number 0 to 9. The units is V.
CC.C - PV current C is an Integer number 0 to 9. The units is A.
DD.DD - Battery voltage D is an Integer number 0 to 9. The units is V.
EE.E - Battery charge current E is an Integer number 0 to 9. The units is A.
FF.F - Load current F is an Integer number 0 to 9. The units is A.
GGGG - Daily electricity generation, G is an Integer ranging from 0 to 9. The units is 0.1KWH.
HHHH - Monthly electricity generation, H is an Integer ranging from 0 to 9. The units is 0.1KWH.
IIII - Annual electricity generation,I is an Integer ranging from 0 to 9. The units is 0.1KWH.
JJJJ - Total electricity generation, J is an Integer ranging from 0 to 9. The units is 0.1KWH.
KK.KK.KK - Initial start time of equipment Year.month.day
L - Charging state 0: Nocharging 1: CCMode 2: CVMode 3: FloatMode
MM - Fault code
NNN - Heat sink temperature N is an Integer ranging from 0 to 9. The units is °C.
O - Calibrated state 0: Normal 1: Calibrated

Last edited by Mix on Fri Mar 25, 2022 12:55 pm, edited 1 time in total.
elmaya
Posts: 1485
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

@MIX edytuj swój post i użyj "</>”, aby wkleić kody.
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Ponad metodą "setup" dodaj sobie poniższego include i definicję klasy:

Code: Select all

#include <supla/sensor/thermometer.h>

class VirtualThermometer : public Supla::Sensor::Thermometer {
  public:
    double getValue() override {
      return myValue;
    }
    void setValue(double val) {
      myValue = val;
    }
  protected:
    double myValue = TEMPERATURE_NOT_AVAILABLE;
};
Klasa "wirtualnego" termometru będzie wysyłać do Supli cokolwiek ustawisz jej metodą "setValue()". Odświeżanie termometru jest chyba co 10 s.

Tak mniej więcej można tego używać:

Code: Select all

auto t1  = new VirtualThermometer;
auto t2  = new VirtualThermometer;

// jeśli chcesz aby podczas rejestracji wysłałą się poprawna wartość, to gdzieś w "setup" dodaj:
t1->setValue(wartosc_t1);
t2->setValue(wartosc_t2);

// potem w loop:
void loop() {
  SuplaDevice.iterate();
  odczytaj_moje_parametry();
  t1->setValue(jakas_wartosc_1);
  t2->setValue(jakas_wartosc_2);  
  }
W "odczytaj_moje_parametry" dajesz swoje metody do odczytania danych i jak już je masz w postaci double'a, to ustawiasz na termometrach.
Ta cała część "odczytaj" i "setValue" może być wykonywana rzadziej niż co iterację loopa. Oczywiście wszystko zależy od tego jak te dane są odczytywane itp.
Najlepsze suple dla Twojego domu :mrgreen:
Zibi
Posts: 646
Joined: Wed Jul 31, 2019 9:20 am
Location: Białogard

Post

@klew czy można te informacje wyświetlić w Supli 2 dwie cyfry po przeciknu? Robie pomiar napięcia akumulatora i temp w samochodzie i po 433mhz wysyłam do Supli, ale brakuje mi żeby po przecinku były dwie cyfry np 12.55V.
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Zibi wrote: Sat Mar 26, 2022 6:05 pm @klew czy można te informacje wyświetlić w Supli 2 dwie cyfry po przeciknu? Robie pomiar napięcia akumulatora i temp w samochodzie i po 433mhz wysyłam do Supli, ale brakuje mi żeby po przecinku były dwie cyfry np 12.55V.
Nie da się zmienić wyświetlanych wartości w apce. Ale przechowywane są chyba z większą precyzją, bo na wykresach są dwa miejsca po przecinku
Najlepsze suple dla Twojego domu :mrgreen:
Mix
Posts: 6
Joined: Mon Feb 04, 2019 9:43 am

Post

Dziękuję za pomoc wygląda na to że działa i przesyła wartości do SUPLI, zobaczymy jak będzie z stabilnością.
Ponieważ korzystam tutaj z SoftwareSerial do komunikacji z ładowarką, idealnie było by wykorzystać sprzętowy port Serial, ale z tego co widzę to SUPLA wyświetla na nim swoje dane.
Jeszcze raz dziękuję za pomoc :)

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.
*/

#include <SuplaDevice.h>
// Add include to virtual sensor
#include <supla/sensor/thermometer.h>
#include <supla/network/esp_wifi.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(14, 12); // RX, TX //ESP8266 D5 = 14 , D6 = 12

unsigned long porzedniCzas = 0;
const long interwal = 5000;
String odczyt = "(126.6 11.1 19.91 11.1 00.0 00000 00000 00000 00000 21.08.03 0 03 023 0u";
double PVnapiecie = 123.4;
double AKUnapiecie = 12.3;


class VirtualThermometer : public Supla::Sensor::Thermometer {
  public:
    double getValue() override {
      return myValue;
    }
    void setValue(double val) {
      myValue = val;
    }
  protected:
    double myValue = TEMPERATURE_NOT_AVAILABLE;
};

void odczytPV()
{
  PVnapiecie = odczyt.substring(1,6).toFloat();
  AKUnapiecie = odczyt.substring(12,16).toFloat();
}

Supla::ESPWifi wifi("SSID", "PASSWD");

auto t1  = new VirtualThermometer;
auto t2  = new VirtualThermometer;

void setup() {

  Serial.begin(115200);
  mySerial.begin(2400);
  
  // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {GUID};

  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {AUTHKEY};

  /*
   * Having your device already registered at cloud.supla.org,
   * you want to change CHANNEL sequence or remove any of them,
   * then you must also remove the device itself from cloud.supla.org.
   * Otherwise you will get "Channel conflict!" error.
   */

  t1->setValue(PVnapiecie);
  t2->setValue(AKUnapiecie);
      
  /*
   * SuplaDevice Initialization.
   * Server address, LocationID and LocationPassword are available at https://cloud.supla.org 
   * If you do not have an account, you can create it at https://cloud.supla.org/account/create
   * SUPLA and SUPLA CLOUD are free of charge
   * 
   */

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    "svr.supla.org",  // SUPLA server address
                    "[email protected]",   // Email address used to login to Supla Cloud
                    AUTHKEY);          // Authorization key
    
}

void loop() {
  SuplaDevice.iterate();


unsigned long bierzacyCzas = millis();

  if (bierzacyCzas - porzedniCzas >= interwal) {
    porzedniCzas = bierzacyCzas;
      mySerial.println("QRTV");
      odczyt = (mySerial.readString()); 
      odczytPV();

    t1->setValue(PVnapiecie);
    t2->setValue(AKUnapiecie);
   
    }
}
Zibi
Posts: 646
Joined: Wed Jul 31, 2019 9:20 am
Location: Białogard

Post

Ja również dziękuję za podanie przykladu testuję z lora i działa świetnie właśnie testuję.
@klew czy jest taka opcja tylko na temp i wilgotnośc? Wirtualny dht22 lub inny? Czy jest jakiś nieoficjalny kanał na napięcie ta literka C przy napięciu trochę drażni :roll:

Return to “Pomoc”