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