Analogowy wyświetlacz temperatur i ciśnienia - linki bezpośrednie (Vintage)

kozus
Posts: 13
Joined: Tue Jun 07, 2022 9:15 am
Location: Katowice

Post

Witam wszystkich suplowiczów
Jest to mój pierwszy post ale nie potrafię sobie poradzić już od miesiąca i dla tego szukam pomocy na forum, mimo że szukałem czegoś podobnego na forum lecz nie znalazłem, dla kogoś może będzie to proste i pomoże. Oryginalny wyświetlacz linków bezpośrednich jest super ale chciałem zrobić przyjacielowi wyświetlacz analogowy (Vintage) aby używał serva jako wskaźnik temperatur i ciśnienia, przyjaciel posiada basen więc chcę aby wskaźniki pokazywały temp. zewnętrzna, temp. wody a ciśnienie to taki dodatek, trzy zegary okrągłe z ładnego drewna ze wskazówkami miały być :), ale że nie jestem programistą utknąłem, mianowicie servo nie ustawia się mimo że w porcie szeregowym wskazania są pokazuje temperatury z linków bez. ale serwa ani rusz. proszę o pomoc.
kod z supi rozdzieliłem sleshem ////////////////////////////
kod:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
#include <Servo.h>
#include <SuplaDevice.h>

/////////////////////////////////////////////SUPLA//////////////////////////////////////////////

#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/control/sequence_button.h>

// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
// Arduino Mega with EthernetShield W5100:
#include <supla/network/ethernet_shield.h>
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Supla::EthernetShield ethernet(mac);

// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
// ESP8266 and ESP32 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("LOGIN", "HASŁO");
#endif

/////////////////////////////////////////////////////////////////////////////////////////////


const char* host1 = "LINK"; // Link bezpośredni do odczytu temperatury zewnętrznej
const char* host2 = "LINK"; // Link bezpośredni do odczytu temperatury wewnętrznej
const char* host3 = "LINK"; // Link bezpośredni do odczytu ciśnienia

const int servoPin1 = D6; // Pin, na którym jest podłączone pierwsze serwo (temperatura zewnętrzna)
const int servoPin2 = D7; // Pin, na którym jest podłączone drugie serwo (temperatura wewnętrzna)
const int servoPin3 = D8; // Pin, na którym jest podłączone trzecie serwo (ciśnienie)

Servo servo1; // Obiekt pierwszego serwa (temperatura zewnętrzna)
Servo servo2; // Obiekt drugiego serwa (temperatura wewnętrzna)
Servo servo3; // Obiekt trzeciego serwa (ciśnienie)


unsigned long times;

// Przelicza temperaturę na wartość kąta serwa w przedziale 0-180
int mapTemperatureToServoAngle(double temperature) {
// Mapowanie wartości temperatury na zakres kątów serwa
return map(temperature, -40, 40, 0, 180);
}

// Przelicza ciśnienie na wartość kąta serwa w przedziale 0-180
int mapPressureToServoAngle(double pressure) {
// Mapowanie wartości ciśnienia na zakres kątów serwa
return map(pressure, 900, 1200, 0, 180);
}

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

//////////////////////////////////////////////////////SUPLA////////////////////////////////////////////////////////

// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {0x2D,0x4E,0xD0,0x61,0xD7,..............................,0x23,0xBB,0x15,0x44,0xB8};

// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0xB0,0x9E,0x15,0x18,0x...................................,0x6C,0x0E,0xA5,0x9A,0x48};

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

auto secretRelay = new Supla::Control::Relay(D3, false); // Low level trigger relay on pin 30
auto alarmRelay = new Supla::Control::Relay(D4, false); // Low level trigger relay on pin 31
auto seqButton = new Supla::Control::SequenceButton(D2, true, true); // Button on pin 28 with internal pullUp
// and LOW is considered as "pressed" state

// Sequence of lenghts [ms] of button being presset, released, pressed, released, etc.
// Aplication will print on Serial recorded sequence, so use it to record your rhythm and put it here
uint16_t sequence[30] = {90, 590, 90, 140, 90, 290, 90, 230, 90, 140, 90};

seqButton->setSequence(sequence);
seqButton->setMargin(0.5); // we allow +- 50% deviation of state length compared to matching sequence

// Button will trigger secretRelay when correct rhythm will be detected or alarmRelay otherwise
seqButton->addAction(Supla::TURN_ON, secretRelay, Supla::ON_SEQUENCE_MATCH);
seqButton->addAction(Supla::TURN_ON, alarmRelay, Supla::ON_SEQUENCE_DOESNT_MATCH);

/*
* SuplaDevice Initialization.
* Server address is 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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Inicjalizacja serw
servo1.attach(servoPin1);
servo2.attach(servoPin2);
servo3.attach(servoPin3);
}



void Direct1() {
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, host1); // HTTPS
int httpCode = https.GET();

String json = https.getString();
Serial.println(json); // Wyświetlenie danych na porcie szeregowym

DynamicJsonDocument doc(1024);
deserializeJson(doc, json);

double temperature = doc["depth"];
int servoAngle = mapTemperatureToServoAngle(temperature);
servo1.write(servoAngle);
}

void Direct2() {
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, host2); // HTTPS
int httpCode = https.GET();

String json = https.getString();
Serial.println(json); // Wyświetlenie danych na porcie szeregowym

DynamicJsonDocument doc(1024);
deserializeJson(doc, json);

double temperature = doc["depth"];
int servoAngle = mapTemperatureToServoAngle(temperature);
servo2.write(servoAngle);
}

void Direct3() {
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, host3); // HTTPS
int httpCode = https.GET();

String json = https.getString();
Serial.println(json); // Wyświetlenie danych na porcie szeregowym

DynamicJsonDocument doc(1024);
deserializeJson(doc, json);

double pressure = doc["depth"];
int servoAngle = mapPressureToServoAngle(pressure);
servo3.write(servoAngle);
}

void loop() {
// Oczekiwanie na połączenie z WiFi
if (WiFi.status() == WL_CONNECTED) {
if (millis() - times >= 20000) {
times = millis();

Direct1();
Direct2();
Direct3();
}
}
SuplaDevice.iterate();
delay(100);
}
kozus
Posts: 13
Joined: Tue Jun 07, 2022 9:15 am
Location: Katowice

Post

Jest ktoś kto by mi pomógł ? nawet rzucił jakiś pomysł naprowadził plis ;)
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Ja bym zaczął od wyrzucenia całego nieużywanego kodu.
Jeśli ten program ma jedynie czytać linki bezpośrednie i sterować analogowym wyświetlaczem, to nie potrzebujesz tutaj używać niczego związanego z SuplaDevice
Najlepsze suple dla Twojego domu :mrgreen:
kozus
Posts: 13
Joined: Tue Jun 07, 2022 9:15 am
Location: Katowice

Post

klew wrote: Fri Jun 30, 2023 5:20 am Ja bym zaczął od wyrzucenia całego nieużywanego kodu.
Jeśli ten program ma jedynie czytać linki bezpośrednie i sterować analogowym wyświetlaczem, to nie potrzebujesz tutaj używać niczego związanego z SuplaDevice
W sumie masz rację , użyłem suplę aby pokazywało urządzenie w cloud czy jest załączone, też tak już próbowałem bez programu supla i jest ten sam problem, szeregowy pokazuje odczyt a program nie odczytuje by ustawić serwo :(

Mogłem uczyć się programowania a nie rzucać kamieniami na szkołę ehhhhhhhh , było by o wiele prościej :D
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

kozus wrote: Fri Jun 30, 2023 9:32 am W sumie masz rację , użyłem suplę aby pokazywało urządzenie w cloud czy jest załączone, też tak już próbowałem bez programu supla i jest ten sam problem, szeregowy pokazuje odczyt a program nie odczytuje by ustawić serwo :(

Mogłem uczyć się programowania a nie rzucać kamieniami na szkołę ehhhhhhhh , było by o wiele prościej :D
Wstaw sobie jakieś logowanie przed metodami:

Code: Select all

  servo1.write(servoAngle);
i wyświetlaj jaki kąt tam się ustawia.

Jeśli nie działa, to zacznij od jakiegoś przykładu z biblioteki "Servo" i spradź, czy działa Tobie sterowanie.
Najlepsze suple dla Twojego domu :mrgreen:
kozus
Posts: 13
Joined: Tue Jun 07, 2022 9:15 am
Location: Katowice

Post

Dzięki Klew poszedłem za twoją radą i teraz wyświetla co ustawia, wcześniej wyświetlał temp ale to co ustawiał było 0 wiec pokombinowałem i działa. Supla będzie służyć w kodzie do włączenia podświetlenia analogowych zegarów diodami led.
port szer.:
{"connected":true,"temperature":30.889999}
Odczytana temperatura dla serwa 1: 30.89
Odczytana temperatura: 30.89
Przeliczony kąt serwa: 158
Ustawiany kąt serwa 1: 158
{"connected":true,"temperature":27.059999}
Odczytana temperatura dla serwa 2: 27.06
Odczytana temperatura: 27.06
Przeliczony kąt serwa: 151
Ustawiany kąt serwa 2: 151
{"connected":true,"value":1019.682983}
Odczytane ciśnienie dla serwa 3: 1019.68
Odczytane ciśnienie: 1019.68
Przeliczony kąt serwa: 71
Ustawiany kąt serwa 3: 71
kozus
Posts: 13
Joined: Tue Jun 07, 2022 9:15 am
Location: Katowice

Post

Cały kod działający dla tych co by chcieli wypróbować:

Code: Select all

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
#include <Servo.h>


///////////////////////////////////////////////////////////////////////////////////////////

#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/control/sequence_button.h>

// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
  // Arduino Mega with EthernetShield W5100:
  #include <supla/network/ethernet_shield.h>
  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  Supla::EthernetShield ethernet(mac);

  // Arduino Mega with ENC28J60:
  // #include <supla/network/ENC28J60.h>
  // Supla::ENC28J60 ethernet(mac);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
  // ESP8266 and ESP32 based board:
  #include <supla/network/esp_wifi.h>
  Supla::ESPWifi wifi("????????", "?????????");
#endif

/////////////////////////////////////////////////////////////////////////////////////////////


const char* host1 = "LINK"; // Link do odczytu temperatury zewnętrznej
const char* host2 = "LINK"; // Link do odczytu temperatury wewnętrznej
const char* host3 = "LINK"; // Link do odczytu ciśnienia

const int servoPin1 = D6;  // Pin, na którym jest podłączone pierwsze serwo (temperatura zewnętrzna)
const int servoPin2 = D7; // Pin, na którym jest podłączone drugie serwo (temperatura wewnętrzna)
const int servoPin3 = D8; // Pin, na którym jest podłączone trzecie serwo (ciśnienie)

Servo servo1;  // Obiekt pierwszego serwa (temperatura zewnętrzna)
Servo servo2;  // Obiekt drugiego serwa (temperatura wewnętrzna)
Servo servo3;  // Obiekt trzeciego serwa (ciśnienie)


unsigned long times;

// Przelicza temperaturę na wartość kąta serwa w przedziale 0-180
int mapTemperatureToServoAngle(double temperature) {
  // Ograniczanie temperatury do zakresu -40°C do 40°C
  temperature = constrain(temperature, -40, 40);
  // Mapowanie wartości temperatury na zakres kątów serwa
  int servoAngle = map(temperature, -40, 40, 0, 180);

  Serial.print("Odczytana temperatura: ");
  Serial.println(temperature);
  Serial.print("Przeliczony kąt serwa: ");
  Serial.println(servoAngle);

  return servoAngle;
}

// Przelicza ciśnienie na wartość kąta serwa w przedziale 0-180
int mapPressureToServoAngle(double pressure) {
  // Ograniczanie ciśnienia do zakresu 900 do 1200
  pressure = constrain(pressure, 900, 1200);
  // Mapowanie wartości ciśnienia na zakres kątów serwa
  int servoAngle = map(pressure, 900, 1200, 0, 180);

  Serial.print("Odczytane ciśnienie: ");
  Serial.println(pressure);
  Serial.print("Przeliczony kąt serwa: ");
  Serial.println(servoAngle);

  return servoAngle;
}

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] = {???????????????????};
 
  /*
   * 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.
   */
    
  auto secretRelay = new Supla::Control::Relay(D3, false); // Low level trigger relay on pin 30 
  auto alarmRelay = new Supla::Control::Relay(D4, false);  // Low level trigger relay on pin 31
  auto seqButton = new Supla::Control::SequenceButton(D2, true, true); // Button on pin 28 with internal pullUp 
                                                                       // and LOW is considered as "pressed" state

  // Sequence of lenghts [ms] of button being presset, released, pressed, released, etc.
  // Aplication will print on Serial recorded sequence, so use it to record your rhythm and put it here
  uint16_t sequence[30] = {90, 590, 90, 140, 90, 290, 90, 230, 90, 140, 90};

  seqButton->setSequence(sequence);
  seqButton->setMargin(0.5);  // we allow +- 50% deviation of state length compared to matching sequence

  // Button will trigger secretRelay when correct rhythm will be detected or alarmRelay otherwise
  seqButton->addAction(Supla::TURN_ON, secretRelay, Supla::ON_SEQUENCE_MATCH);
  seqButton->addAction(Supla::TURN_ON, alarmRelay, Supla::ON_SEQUENCE_DOESNT_MATCH);
 
  /*
   * SuplaDevice Initialization.
   * Server address is 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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  // Inicjalizacja serw
  servo1.attach(servoPin1);
  servo2.attach(servoPin2);
  servo3.attach(servoPin3);
}

void Direct1() {
  std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure);
  client->setInsecure();
  HTTPClient https;
  https.begin(*client, host1); // HTTPS
  int httpCode = https.GET();

  if (httpCode > 0) {
    String json = https.getString();
    Serial.println(json); // Wyświetlenie danych na porcie szeregowym

    DynamicJsonDocument doc(1024);
    deserializeJson(doc, json);

    double temperature = doc["temperature"];
    Serial.print("Odczytana temperatura dla serwa 1: ");
    Serial.println(temperature); // Wyświetlenie odczytanej temperatury

    int servoAngle = mapTemperatureToServoAngle(temperature);

    Serial.print("Ustawiany kąt serwa 1: ");
    Serial.println(servoAngle); // Wyświetlenie ustawianego kąta

    servo1.write(servoAngle);
  }
  else {
    Serial.println("Błąd HTTP");
  }

  https.end();
}


void Direct2() {
  std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure);
  client->setInsecure();
  HTTPClient https;
  https.begin(*client, host2); // HTTPS
  int httpCode = https.GET();

  if (httpCode > 0) {
    String json = https.getString();
    Serial.println(json); // Wyświetlenie danych na porcie szeregowym

    DynamicJsonDocument doc(1024);
    deserializeJson(doc, json);

    double temperature = doc["temperature"];
    Serial.print("Odczytana temperatura dla serwa 2: ");
    Serial.println(temperature); // Wyświetlenie odczytanej temperatury

    int servoAngle = mapTemperatureToServoAngle(temperature);

    Serial.print("Ustawiany kąt serwa 2: ");
    Serial.println(servoAngle); // Wyświetlenie ustawianego kąta

    servo2.write(servoAngle);
  }
  else {
    Serial.println("Błąd HTTP");
  }

  https.end();
}

void Direct3() {
  std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure);
  client->setInsecure();
  HTTPClient https;
  https.begin(*client, host3); // HTTPS
  int httpCode = https.GET();

  if (httpCode > 0) {
    String json = https.getString();
    Serial.println(json); // Wyświetlenie danych na porcie szeregowym

    DynamicJsonDocument doc(1024);
    deserializeJson(doc, json);

    double pressure = doc["value"];
    Serial.print("Odczytane ciśnienie dla serwa 3: ");
    Serial.println(pressure); // Wyświetlenie odczytanego ciśnienia

    int servoAngle = mapPressureToServoAngle(pressure);

    Serial.print("Ustawiany kąt serwa 3: ");
    Serial.println(servoAngle); // Wyświetlenie ustawianego kąta

    servo3.write(servoAngle);
  }
  else {
    Serial.println("Błąd HTTP");
  }

  https.end();
}


void loop() {
  // Oczekiwanie na połączenie z WiFi
  if (WiFi.status() == WL_CONNECTED) {
    if (millis() - times >= 20000) {
      times = millis();

      Direct1();
      Direct2();
      Direct3();
    }
  }
  SuplaDevice.iterate();
  delay(100);
}
Last edited by kozus on Fri Sep 15, 2023 9:54 am, edited 1 time in total.
User avatar
Robert Błaszczak
Posts: 5222
Joined: Sat Dec 22, 2018 8:55 pm
Location: Zielona Góra
Has thanked: 37 times
Been thanked: 27 times

Post

@kozus, dla czytelności wątku oraz kodu warto stosować przycisk </> przy pisaniu postu. Wygląda to wtedy tak:
Kod programu wklejasz wtedy pomiędzy znaczniki [ code ] i [ /code ].

Code: Select all

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
#include <Servo.h>


///////////////////////////////////////////////////////////////////////////////////////////

#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/control/sequence_button.h>

// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
// Arduino Mega with EthernetShield W5100:
#include <supla/network/ethernet_shield.h>
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Supla::EthernetShield ethernet(mac);

// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
// ESP8266 and ESP32 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("????????", "?????????");
#endif

/////////////////////////////////////////////////////////////////////////////////////////////


const char* host1 = "LINK"; // Link do odczytu temperatury zewnętrznej
const char* host2 = "LINK"; // Link do odczytu temperatury wewnętrznej
const char* host3 = "LINK"; // Link do odczytu ciśnienia

const int servoPin1 = D6; // Pin, na którym jest podłączone pierwsze serwo (temperatura zewnętrzna)
const int servoPin2 = D7; // Pin, na którym jest podłączone drugie serwo (temperatura wewnętrzna)
const int servoPin3 = D8; // Pin, na którym jest podłączone trzecie serwo (ciśnienie)

Servo servo1; // Obiekt pierwszego serwa (temperatura zewnętrzna)
Servo servo2; // Obiekt drugiego serwa (temperatura wewnętrzna)
Servo servo3; // Obiekt trzeciego serwa (ciśnienie)


unsigned long times;

// Przelicza temperaturę na wartość kąta serwa w przedziale 0-180
int mapTemperatureToServoAngle(double temperature) {
// Ograniczanie temperatury do zakresu -40°C do 40°C
temperature = constrain(temperature, -40, 40);
// Mapowanie wartości temperatury na zakres kątów serwa
int servoAngle = map(temperature, -40, 40, 0, 180);

Serial.print("Odczytana temperatura: ");
Serial.println(temperature);
Serial.print("Przeliczony kąt serwa: ");
Serial.println(servoAngle);

return servoAngle;
}

// Przelicza ciśnienie na wartość kąta serwa w przedziale 0-180
int mapPressureToServoAngle(double pressure) {
// Ograniczanie ciśnienia do zakresu 900 do 1200
pressure = constrain(pressure, 900, 1200);
// Mapowanie wartości ciśnienia na zakres kątów serwa
int servoAngle = map(pressure, 900, 1200, 0, 180);

Serial.print("Odczytane ciśnienie: ");
Serial.println(pressure);
Serial.print("Przeliczony kąt serwa: ");
Serial.println(servoAngle);

return servoAngle;
}

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

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

auto secretRelay = new Supla::Control::Relay(D3, false); // Low level trigger relay on pin 30
auto alarmRelay = new Supla::Control::Relay(D4, false); // Low level trigger relay on pin 31
auto seqButton = new Supla::Control::SequenceButton(D2, true, true); // Button on pin 28 with internal pullUp
// and LOW is considered as "pressed" state

// Sequence of lenghts [ms] of button being presset, released, pressed, released, etc.
// Aplication will print on Serial recorded sequence, so use it to record your rhythm and put it here
uint16_t sequence[30] = {90, 590, 90, 140, 90, 290, 90, 230, 90, 140, 90};

seqButton->setSequence(sequence);
seqButton->setMargin(0.5); // we allow +- 50% deviation of state length compared to matching sequence

// Button will trigger secretRelay when correct rhythm will be detected or alarmRelay otherwise
seqButton->addAction(Supla::TURN_ON, secretRelay, Supla::ON_SEQUENCE_MATCH);
seqButton->addAction(Supla::TURN_ON, alarmRelay, Supla::ON_SEQUENCE_DOESNT_MATCH);

/*
* SuplaDevice Initialization.
* Server address is 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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Inicjalizacja serw
servo1.attach(servoPin1);
servo2.attach(servoPin2);
servo3.attach(servoPin3);
}

void Direct1() {
std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, host1); // HTTPS
int httpCode = https.GET();

if (httpCode > 0) {
String json = https.getString();
Serial.println(json); // Wyświetlenie danych na porcie szeregowym

DynamicJsonDocument doc(1024);
deserializeJson(doc, json);

double temperature = doc["temperature"];
Serial.print("Odczytana temperatura dla serwa 1: ");
Serial.println(temperature); // Wyświetlenie odczytanej temperatury

int servoAngle = mapTemperatureToServoAngle(temperature);

Serial.print("Ustawiany kąt serwa 1: ");
Serial.println(servoAngle); // Wyświetlenie ustawianego kąta

servo1.write(servoAngle);
}
else {
Serial.println("Błąd HTTP");
}

https.end();
}


void Direct2() {
std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, host2); // HTTPS
int httpCode = https.GET();

if (httpCode > 0) {
String json = https.getString();
Serial.println(json); // Wyświetlenie danych na porcie szeregowym

DynamicJsonDocument doc(1024);
deserializeJson(doc, json);

double temperature = doc["temperature"];
Serial.print("Odczytana temperatura dla serwa 2: ");
Serial.println(temperature); // Wyświetlenie odczytanej temperatury

int servoAngle = mapTemperatureToServoAngle(temperature);

Serial.print("Ustawiany kąt serwa 2: ");
Serial.println(servoAngle); // Wyświetlenie ustawianego kąta

servo2.write(servoAngle);
}
else {
Serial.println("Błąd HTTP");
}

https.end();
}

void Direct3() {
std::unique_ptr<WiFiClientSecure> client(new WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, host3); // HTTPS
int httpCode = https.GET();

if (httpCode > 0) {
String json = https.getString();
Serial.println(json); // Wyświetlenie danych na porcie szeregowym

DynamicJsonDocument doc(1024);
deserializeJson(doc, json);

double pressure = doc["value"];
Serial.print("Odczytane ciśnienie dla serwa 3: ");
Serial.println(pressure); // Wyświetlenie odczytanego ciśnienia

int servoAngle = mapPressureToServoAngle(pressure);

Serial.print("Ustawiany kąt serwa 3: ");
Serial.println(servoAngle); // Wyświetlenie ustawianego kąta

servo3.write(servoAngle);
}
else {
Serial.println("Błąd HTTP");
}

https.end();
}


void loop() {
// Oczekiwanie na połączenie z WiFi
if (WiFi.status() == WL_CONNECTED) {
if (millis() - times >= 20000) {
times = millis();

Direct1();
Direct2();
Direct3();
}
}
SuplaDevice.iterate();
delay(100);
}
Pozdrawiam
Robert Błaszczak


Moja prywatna strona: www.blaszczak.pl
kozus
Posts: 13
Joined: Tue Jun 07, 2022 9:15 am
Location: Katowice

Post

Dzięki będę pamiętał :) jestem troszkę mądrzejszy :P

Return to “Ogólna dyskusja”