U mnie na przeglądarce Safari macOS czyta "format=json" bez problemu dostaje odczyt w formacie json z serwera nawet linki z Supla MEW-1 śmigają bez problemuklew wrote: Fri May 05, 2023 12:32 pm
Rzewczywiście coś Cloud przestał respektować parametr "format=json".
Linki bezpośrednie odczyt
-
jamsjamsen
- Posts: 72
- Joined: Sat Jan 28, 2017 11:08 am
- Location: 0xE952
Byłem na Supla Offline Party 2023 & 2024 ;
-
nebraska
- Posts: 204
- Joined: Thu Dec 08, 2022 3:00 pm
- Been thanked: 1 time
@klew Dziękuje po raz kolejny. W linijce mamklew wrote: Fri May 05, 2023 12:32 pmRzewczywiście coś Cloud przestał respektować parametr "format=json". Nie wiem jak to prosto z przeglądarki objeść.nebraska wrote: Fri May 05, 2023 11:21 am Mam odpowiedź wklejałem róznie już ten link i nic nie czyta z tego kanału wirtualnego odległości.
Rezultat wykonania jest zaprezentowany jako strona internetowa, ponieważ Ty (lub Twoja przeglądarka) poprosiła o odpowiedź w formacie HTML.
Jeśli chcesz użyć linku bezpośredniego w innym oprogramowaniu, dodaj odpowiedni nagłówek żądania by otrzymać odpowiedź łatwiejszą w przetworzeniu.
Accept: application/json
Natomiast możesz zerknąć do źródeł odczytanej strony (prawy przycisk myszy i "pokaż źródło", albo skrót "ctrl+u" - na chrome i FF sprawdzałem).
Tam poszukaj słowa: "state":
Razem z " oraz :
Powinna tam być widoczna wartość tego jsona, oraz jakie są parametry.
U mnie na THW widać tam:
"state":{"connected":true,"humidity":38.858,"temperature":25.605}
state":{"connected":true,"depth":4.01}};
Wystarczyło zmienić na "depth" i czyta.
Wielkie dzięki mistrzu.
Pytanie czy można odczytać dwa miejsca po przecinku, teraz mi czyta 4.0 Czy będzie zaokrąglał? tak informacyjnie pytam.
-
jamsjamsen
- Posts: 72
- Joined: Sat Jan 28, 2017 11:08 am
- Location: 0xE952
trzeba zmienić:nebraska wrote: Sun May 07, 2023 12:08 pm
Pytanie czy można odczytać dwa miejsca po przecinku, teraz mi czyta 4.0 Czy będzie zaokrąglał? tak informacyjnie pytam.
dtostrf(Temp, 4, 1, charVal);
na:
dtostrf(Temp, 4, 2, charVal);
Byłem na Supla Offline Party 2023 & 2024 ;
-
nebraska
- Posts: 204
- Joined: Thu Dec 08, 2022 3:00 pm
- Been thanked: 1 time
Bardzo dziękuje.jamsjamsen wrote: Sun May 07, 2023 12:33 pmtrzeba zmienić:nebraska wrote: Sun May 07, 2023 12:08 pm
Pytanie czy można odczytać dwa miejsca po przecinku, teraz mi czyta 4.0 Czy będzie zaokrąglał? tak informacyjnie pytam.
dtostrf(Temp, 4, 1, charVal);
na:
dtostrf(Temp, 4, 2, charVal);
@ jamsjamsen a mógłbyś przerobić ten twój przykład tak żebym mógł dodać więcej odczytów linków. Próbowałem ale cos mi nie wychodzi.
Np dopisać drugi odczyt to juz dalej dodam resztę.
Code: Select all
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
const char* ssid = "XXXXX"; // Nazwa WiFi
const char* password = "XXXX"; // Hasło Wifi
const char* host1 = "https://svrx.supla.org/direct/xxxxxxxxxxformat=json";
unsigned long times;
void setup() {
Serial.begin(115200);
Serial.println();
//Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
}
void Direct() {
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();
//https.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
double Temp = doc["depth"]; // temperature , humidity, depth(virtualny czujnik odleglosci),
char charVal[10];
dtostrf(Temp, 4, 2, charVal);
Serial.println(charVal);
}
void loop() {
// wait for WiFi connection
if ((WiFi.status() == WL_CONNECTED)) {
if(millis() - times >= 20000){
times=millis();
HTTPClient https;
Direct();
https.end();
delay(100);
}
}}-
jamsjamsen
- Posts: 72
- Joined: Sat Jan 28, 2017 11:08 am
- Location: 0xE952
#include <Arduino.h>nebraska wrote: Sun May 07, 2023 1:46 pm
Bardzo dziękuje.
@ jamsjamsen a mógłbyś przerobić ten twój przykład tak żebym mógł dodać więcej odczytów linków. Próbowałem ale cos mi nie wychodzi.
Np dopisać drugi odczyt to juz dalej dodam resztę.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
const char* ssid = "XXXXX"; // Nazwa WiFi
const char* password = "XXXX"; // Hasło Wifi
const char* host1 = "https://svrx.supla.org/direct/xxxxxxxxx ... ormat=json";
const char* host2 = "https://svrx.supla.org/direct/xxxxxxxxx ... ormat=json";
unsigned long times;
void setup() {
Serial.begin(115200);
Serial.println();
//Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
}
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();
//https.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
double Temp = doc["depth"]; // temperature , humidity, depth(virtualny czujnik odleglosci),
char charVal[10];
dtostrf(Temp, 4, 2, charVal);
Serial.println(charVal);
}
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();
//https.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
double Temp = doc["depth"]; // temperature , humidity, depth(virtualny czujnik odleglosci),
char charVal1[10];
dtostrf(Temp, 4, 2, charVal1);
Serial.println(charVal1);
}
void loop() {
// wait for WiFi connection
if ((WiFi.status() == WL_CONNECTED)) {
if(millis() - times >= 20000){
times=millis();
HTTPClient https;
Direct1();
Direct2();
https.end();
delay(100);
}
}}
Byłem na Supla Offline Party 2023 & 2024 ;
-
nebraska
- Posts: 204
- Joined: Thu Dec 08, 2022 3:00 pm
- Been thanked: 1 time
@jamsjamsen Bardzo bardzo dziękuje odbiera pięknie dwie wartośći.jamsjamsen wrote: Sun May 07, 2023 2:42 pm#include <Arduino.h>nebraska wrote: Sun May 07, 2023 1:46 pm
Bardzo dziękuje.
@ jamsjamsen a mógłbyś przerobić ten twój przykład tak żebym mógł dodać więcej odczytów linków. Próbowałem ale cos mi nie wychodzi.
Np dopisać drugi odczyt to juz dalej dodam resztę.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
const char* ssid = "XXXXX"; // Nazwa WiFi
const char* password = "XXXX"; // Hasło Wifi
const char* host1 = "https://svrx.supla.org/direct/xxxxxxxxx ... ormat=json";
const char* host2 = "https://svrx.supla.org/direct/xxxxxxxxx ... ormat=json";
unsigned long times;
void setup() {
Serial.begin(115200);
Serial.println();
//Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
}
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();
//https.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
double Temp = doc["depth"]; // temperature , humidity, depth(virtualny czujnik odleglosci),
char charVal[10];
dtostrf(Temp, 4, 2, charVal);
Serial.println(charVal);
}
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();
//https.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
double Temp = doc["depth"]; // temperature , humidity, depth(virtualny czujnik odleglosci),
char charVal1[10];
dtostrf(Temp, 4, 2, charVal1);
Serial.println(charVal1);
}
void loop() {
// wait for WiFi connection
if ((WiFi.status() == WL_CONNECTED)) {
if(millis() - times >= 20000){
times=millis();
HTTPClient https;
Direct1();
Direct2();
https.end();
delay(100);
}
}}
-
nebraska
- Posts: 204
- Joined: Thu Dec 08, 2022 3:00 pm
- Been thanked: 1 time
Jeszcze chciałem spróbować to ożenić z cfg, żeby na stronie konfiguracji mieć możliwość wklejenia linków, ale coś nie mogę uzyskać odczytu.
Code: Select all
#define STATUS_LED_GPIO 2
#define RELAY_GPIO 5
#define BUTTON_CFG_RELAY_GPIO 0 // Przycisk Konfiguracji D3/GPIO 0
#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
#include <supla/control/action_trigger.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/events.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/network/html/custom_parameter.h>
#include <supla/network/html/custom_text_parameter.h>
#include <supla/network/html/text_cmd_input_parameter.h>
#include <supla/network/html/select_cmd_input_parameter.h>
#include <WiFiClientSecure.h>
#include <supla/storage/eeprom.h>
#include "SPI.h"
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
Supla::Eeprom eeprom;
Supla::ESPWifi wifi;
Supla::EspWebServer suplaServer;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true);
unsigned long times;
char charVal[10];
const char PARAM[] = "param";
char host1[200] = {};
void Direct1() {
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
https.begin(*client, String(host1));// HTTPS
Serial.print("Link");
Serial.println(host1);
int httpCode = https.GET();
String json = https.getString();
//https.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
double Temp = doc["temperature"]; // temperature , humidity, depth(virtualny czujnik odleglosci),
dtostrf(Temp, 4, 1, charVal); // Wartosc 2 oznacza dwa miejsca wartosci po przecinku, 1 jedno miejsce po przecinku.
Serial.println(charVal);
}
void setup() {
Serial.begin(115200);
auto r1 = new Supla::Control::Relay(RELAY_GPIO);
auto at1 = new Supla::Control::ActionTrigger();
auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
buttonCfgRelay->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1);
at1->setRelatedChannel(r1);
at1->attach(buttonCfgRelay);
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
new Supla::Html::DeviceInfo(&SuplaDevice);
new Supla::Html::WifiParameters;
new Supla::Html::ProtocolParameters;
new Supla::Html::StatusLedParameters;
new Supla::Html::CustomTextParameter(PARAM, "Link Bezposredni", 200);
SuplaDevice.setName("SUPLA-DIRECT-LINK");
SuplaDevice.begin();
//------------------ INPUT Tekstowy -------------------------------------------------
if (Supla::Storage::ConfigInstance()->getString(PARAM, host1, 200)) {
SUPLA_LOG_DEBUG(" **** Param[%s]: %s", PARAM, host1);
} else {
SUPLA_LOG_DEBUG(" **** Param[%s] is not set", PARAM);
}
}
void loop() {
SuplaDevice.iterate();
if (millis() - times >= 20000) {
times = millis();
HTTPClient https;
Direct1();
https.end();
delay(100);
}
}
-
jamsjamsen
- Posts: 72
- Joined: Sat Jan 28, 2017 11:08 am
- Location: 0xE952
Tutaj już chyba tak łatwo nie pójdzie, w tym danym przykładzie nie czyta linku i wartość na serialu to 0.0nebraska wrote: Sun May 07, 2023 4:24 pm Jeszcze chciałem spróbować to ożenić z cfg, żeby na stronie konfiguracji mieć możliwość wklejenia linków, ale coś nie mogę uzyskać odczytu.
Code: Select all
#define STATUS_LED_GPIO 2 #define RELAY_GPIO 5 #define BUTTON_CFG_RELAY_GPIO 0 // Przycisk Konfiguracji D3/GPIO 0 #include <SuplaDevice.h> #include <supla/network/esp_wifi.h> #include <supla/control/relay.h> #include <supla/control/button.h> #include <supla/control/action_trigger.h> #include <supla/device/status_led.h> #include <supla/storage/littlefs_config.h> #include <supla/network/esp_web_server.h> #include <supla/device/supla_ca_cert.h> #include <supla/events.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/network/html/custom_parameter.h> #include <supla/network/html/custom_text_parameter.h> #include <supla/network/html/text_cmd_input_parameter.h> #include <supla/network/html/select_cmd_input_parameter.h> #include <WiFiClientSecure.h> #include <supla/storage/eeprom.h> #include "SPI.h" #include <Arduino.h> #include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClientSecureBearSSL.h> #include <ArduinoJson.h> Supla::Eeprom eeprom; Supla::ESPWifi wifi; Supla::EspWebServer suplaServer; Supla::LittleFsConfig configSupla; Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); unsigned long times; char charVal[10]; const char PARAM[] = "param"; char host1[200] = {}; void Direct1() { std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure); client->setInsecure(); HTTPClient https; https.begin(*client, String(host1));// HTTPS Serial.print("Link"); Serial.println(host1); int httpCode = https.GET(); String json = https.getString(); //https.end(); DynamicJsonDocument doc(1024); deserializeJson(doc, json); double Temp = doc["temperature"]; // temperature , humidity, depth(virtualny czujnik odleglosci), dtostrf(Temp, 4, 1, charVal); // Wartosc 2 oznacza dwa miejsca wartosci po przecinku, 1 jedno miejsce po przecinku. Serial.println(charVal); } void setup() { Serial.begin(115200); auto r1 = new Supla::Control::Relay(RELAY_GPIO); auto at1 = new Supla::Control::ActionTrigger(); auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true); buttonCfgRelay->configureAsConfigButton(&SuplaDevice); buttonCfgRelay->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1); at1->setRelatedChannel(r1); at1->attach(buttonCfgRelay); SuplaDevice.setSuplaCACert(suplaCACert); SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert); new Supla::Html::DeviceInfo(&SuplaDevice); new Supla::Html::WifiParameters; new Supla::Html::ProtocolParameters; new Supla::Html::StatusLedParameters; new Supla::Html::CustomTextParameter(PARAM, "Link Bezposredni", 200); SuplaDevice.setName("SUPLA-DIRECT-LINK"); SuplaDevice.begin(); //------------------ INPUT Tekstowy ------------------------------------------------- if (Supla::Storage::ConfigInstance()->getString(PARAM, host1, 200)) { SUPLA_LOG_DEBUG(" **** Param[%s]: %s", PARAM, host1); } else { SUPLA_LOG_DEBUG(" **** Param[%s] is not set", PARAM); } } void loop() { SuplaDevice.iterate(); if (millis() - times >= 20000) { times = millis(); HTTPClient https; Direct1(); https.end(); delay(100); } }
aż tak dobrze w bibliotekach Supli to ja nie śmigam ;(
Byłem na Supla Offline Party 2023 & 2024 ;
