Męczę się od kilku dni z tym problemem i nie mogę tego przeskoczyć. Napisałem sobie metodę, która wysyła mi powiadomienia do pushbullet, działa bardzo ładnie gdy nie jest połączona ze suplą.
Problem jest taki, że supla lub pushbullet w pewnych momentach blokują lub zabierają sobie połączenie. Efekt jest taki, że nie mogę nawiązać połączenia po przez client.connect(host, 443) ale też jest tak, że gdy nawiążę połączenie po przez client.connect(host, 443) to supla dosstaje timeouta i się rozłącza... oczywiście dzieje się to losowo bo jest tak, że działa wszystko dobrze
jak zakomentuję w pętli SuplaDevice.iterate() to zawsze nawiązuje się poprawie połączenie.
Czy macie jakiś pomysł jak temu zaradzić?
Code: Select all
extern const char* host = "api.pushbullet.com";
extern const char* PushBulletAPIKEY = "xxxxxx";
void sendAndToggl(const String path, const String massage) {
const char* fingerprint = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
BearSSL::WiFiClientSecure client;
client.setTimeout(200);
client.setFingerprint(fingerprint);
//client.setInsecure();
HTTPClient https;
Serial.print("conntecting to server: ");
Serial.println(host);
if (!client.connect(host, 443)) {
Serial.println("connection failed");
client.stop();
return;
} else {
Serial.println("connection host");
}
if (https.begin(client, host, 443, path)) {
https.addHeader("Authorization", "Bearer " + String(PushBulletAPIKEY));
https.addHeader("Content-Type", "application/json");
int httpsCode = https.POST(massage);
if (httpsCode > 0) {
Serial.println(httpsCode);
if (httpsCode == HTTP_CODE_OK) {
Serial.println(https.getString());
}
} else {
Serial.println("failed to GET");
}
https.end();
// client.stop();
} else {
Serial.print("failed to connect to server");
}
}
Code: Select all
void loop() {
SuplaDevice.iterate();
unsigned long now = millis();
turn_bell_on(now);
}
Code: Select all
unsigned long turn_bell_timer = 0;
bool state_bell = false;
bool isBell() {
return digitalRead(PIN_BELL_BUTTON) == LOW;
}
void turn_bell_on(unsigned long now) {
if ( isBell() != state_bell && now - turn_bell_timer ) {
if (isBell()) {
if (now - turn_bell_timer >= 10000) {
Serial.println("dzwonie");
sendNotePush(massageBell, "powiadomienie");
}
}
state_bell = isBell();
turn_bell_timer = now;
}
}
