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();
}