KPOP problem z połączeniem

cbool222
Posts: 4
Joined: Tue Mar 12, 2024 9:43 am

Post

Witajcie
Mam problem z moją stacją, stacja ma wiele czujników: 3xDS18B20, 1x DHT22, 1x SDS010, 1xBH1750 i wiele innych. Wszystko działało na Wirtualnych Termometrach bez problemy. Z nadejściem KPOP chciałem nadać tym czujnikom odpowiednie jednostki przepisująć jednocześnie od zera kod. Problem pojawił się po zmianie VirtualThermometer na GeneralPurposeMeasurement. Supla(Arduino) po zarejestrowaniu na serwerze wysyła dane po czym się resetuje. Arduino potrafi się od kilku do kilkunastu razy tak zresetować po czym się zawiesza.

Macie jakiś pomysł co jest tego powodem?

Kod programu

Code: Select all

#include <SuplaDevice.h>
#include <Wire.h>
#include <SPI.h>

#include <supla/sensor/virtual_thermometer.h>
#include <supla/sensor/virtual_hygromometer.h>
#include <supla/sensor/general_purpose_measurement.h>

#include <BH1750.h>
#include <OneWire.h>

#include <AM2302-Sensor.h>

#ifdef ARDUINO_ARCH_AVR

#include <supla/network/ethernet_shield.h>

uint8_t mac[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
Supla::EthernetShield ethernet(mac);

#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)

#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("your_wifi_ssid", "your_wifi_password");
#endif


#define DHT1PIN 24
#define DHT1TYPE DHT22
#define UVPIN A5
#define WATER1TEMPPIN 26

BH1750 lightMeter;
AM2302::AM2302_Sensor am2302{DHT1PIN};
OneWire ds(WATER1TEMPPIN);

Supla::Sensor::GeneralPurposeMeasurement *SuplaTemp1 = nullptr;
Supla::Sensor::GeneralPurposeMeasurement *SuplaTemp2 = nullptr;
Supla::Sensor::VirtualThermometer *SuplaTemp3 = nullptr;
Supla::Sensor::VirtualThermometer *SuplaTemp4 = nullptr;
Supla::Sensor::VirtualThermometer *SuplaTemp5 = nullptr;
Supla::Sensor::VirtualThermometer *SuplaTemp6 = nullptr;
Supla::Sensor::VirtualThermometer *SuplaTemp7 = nullptr;

//uint8_t ds1addr = { 0x28, 0x8A, 0x25, 0xAD, 0x0F, 0x0, 0x0, 0x7A };
//uint8_t ds2addr = { 0x28, 0xCD, 0x1E, 0xA5, 0x0F, 0x0, 0x0, 0x62 };
//uint8_t ds3addr = { 0x28, 0x07, 0xE4, 0xAC, 0x0F, 0x0, 0x0, 0xBA };

uint8_t Sensor1[8] = { 0x28, 0x8A, 0x25, 0xAD, 0x0F, 0x0, 0x0, 0x7A };
uint8_t Sensor2[8] = { 0x28, 0xCD, 0x1E, 0xA5, 0x0F, 0x0, 0x0, 0x62 };
uint8_t Sensor3[8] = { 0x28, 0x07, 0xE4, 0xAC, 0x0F, 0x0, 0x0, 0xBA };

float OneWireTemp(byte addr[8]) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[9];
  float celsius, fahrenheit;


  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);  // start conversion, with parasite power on at the end

  delay(1000);  // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);  // Read Scratchpad


  for (i = 0; i < 9; i++) {  // we need 9 bytes
    data[i] = ds.read();
  }


  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3;  // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;       // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3;  // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1;  // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  return celsius;
}


void setup() {

  Serial.begin(9600);
  Wire.begin();
  lightMeter.begin();
  am2302.begin();
  // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = { 0x9A, 0xC4, 0x34, 0x1B, 0x33, 0x28, 0x44, 0x5C, 0x9B, 0xA4, 0xF8, 0xFC, 0x01, 0x0D, 0x8B, 0x66 };
  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = { 0xE8, 0xDF, 0xFC, 0xA0, 0xED, 0x48, 0xEC, 0x51, 0x73, 0x4C, 0xFE, 0xB5, 0x0B, 0x46, 0xAB, 0x48 };


  SuplaTemp1 = new Supla::Sensor::GeneralPurposeMeasurement();
  SuplaTemp2 = new Supla::Sensor::GeneralPurposeMeasurement();
  SuplaTemp3 = new Supla::Sensor::VirtualThermometer();
  SuplaTemp4 = new Supla::Sensor::VirtualThermometer();
  SuplaTemp5 = new Supla::Sensor::VirtualThermometer();
  SuplaTemp6 = new Supla::Sensor::VirtualThermometer();
  SuplaTemp7 = new Supla::Sensor::VirtualThermometer();



  SuplaDevice.begin(GUID,                    // Global Unique Identifier
                    "svr111.supla.org",      // SUPLA server address
                    "[email protected]",  // Email address used to login to Supla Cloud
                    AUTHKEY);                // Authorization key
}

void loop() {
  float t1 = OneWireTemp(Sensor1);
  float t2 = OneWireTemp(Sensor2);
  float t3 = OneWireTemp(Sensor3);
  float t4 = am2302.get_Temperature();
  float t5 = am2302.get_Humidity();
  int t6 = analogRead(UVPIN);
  float lux = lightMeter.readLightLevel();

  SuplaDevice.iterate();

  SuplaTemp1->setValue(t1);
  SuplaTemp2->setValue(t2);
  SuplaTemp3->setValue(t3);
  SuplaTemp4->setValue(t4);
  SuplaTemp5->setValue(t5);
  SuplaTemp6->setValue(t6);
  SuplaTemp7->setValue(lux);
}
Logi z Arduino:

Code: Select all

10:01:28.877 -> Supla - starting initialization
10:01:28.910 -> Main storage not configured
10:01:28.942 -> Config storage not configured
10:01:28.975 -> Channel(0) value changed to NaN
10:01:29.008 -> Channel(1) value changed to NaN
10:01:29.040 -> Channel(2) value changed to -275.00
10:01:29.074 -> Channel(3) value changed to -275.00
10:01:29.106 -> Channel(4) value changed to -275.00
10:01:29.172 -> Channel(5) value changed to -275.00
10:01:29.204 -> Channel(6) value changed to -275.00
10:01:29.237 -> GUID: 9AC4341B3328445C9BA4F8FC010D8B66
10:01:29.270 -> Device name: SUPLA-ARDUINO
10:01:29.303 -> Device software version: SDK 24.02-dev
10:01:29.336 -> Initializing network layer
10:01:29.368 -> Network AP/hostname: SUPLA-ARDUINO
10:01:29.401 -> Using Supla protocol version 21
10:01:29.434 -> Current status: [5] SuplaDevice initialized
10:01:29.499 -> Enter normal mode
10:01:32.497 -> Channel(0) value changed to NaN
10:01:32.530 -> Channel(1) value changed to NaN
10:01:32.563 -> Connecting to network...
10:01:33.141 -> DHCP connection result: 1
10:01:33.174 -> localIP: 10.10.64.142
10:01:33.206 -> subnetMask: 255.255.0.0
10:01:33.239 -> gatewayIP: 10.10.0.1
10:01:33.272 -> dnsServerIP: 10.10.1.2
10:01:33.272 -> Establishing NOT encrypted connection with: svr111.supla.org (port: 2015)
10:01:33.370 -> Connected to Supla Server
10:01:33.403 -> Initializing SRPC
10:01:33.435 -> Current status: [10] Register in progress
10:01:33.468 -> CH #0, type: 9000, FuncList: 0x0, default: 0, flags: 0x0, value: [208 00 00 801 79 c0 00 19]
10:01:33.566 -> CH #1, type: 9000, FuncList: 0x0, default: 0, flags: 0x0, value: [208 00 00 801 79 c0 00 19]
10:01:33.665 -> CH #2, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:33.763 -> CH #3, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:33.861 -> CH #4, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:33.960 -> CH #5, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:34.057 -> CH #6, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:34.157 -> Send: [53 55 50 4C 41 ]
10:01:37.163 -> Channel(2) value changed to 22.62
10:01:37.228 -> Channel(3) value changed to 22.40
10:01:37.261 -> Channel(4) value changed to 42.60
10:01:37.293 -> Channel(5) value changed to 0.00
10:01:37.326 -> Channel(6) value changed to 6.66
10:01:37.359 -> Recv: [53 55 50 4C 41 15 01 00 00 00 46 00 00 00 07 00 00 00 03 00 00 00 78 17 01 53 55 50 4C 41 53 55 ]
10:01:37.458 -> Device registered (activity timeout 120 s, server version: 23, server min version: 1)
10:01:37.556 -> Current status: [17] Registered and ready
10:01:37.589 -> Changing activity timeout to 30
10:01:37.655 -> Send: [53 55 50 4C 41 15 02 00 00 00 D2 00 00 00 01 00 00 00 1E ]
10:01:37.720 -> Send: [53 55 50 4C 41 ]
10:01:37.720 -> Send: [53 55 50 4C 41 15 03 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 79 C0 00 19 00 00 F8 C7 ]
10:01:37.851 -> Send: [53 55 50 4C 41 ]
10:01:40.861 -> Channel(0) value changed to 22.93
10:01:40.894 -> Channel(1) value changed to 22.81
10:01:40.927 -> Recv: [50 4C 41 15 02 00 00 00 AD 02 00 00 1B 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
10:01:41.025 -> Send: [53 55 50 4C 41 15 04 00 00 00 67 00 00 00 0E 00 00 00 01 00 00 00 00 00 79 C0 00 19 00 D0 36 40 ]
10:01:41.155 -> Send: [53 55 50 4C 41 ]
10:01:44.170 -> Recv: [00 00 00 00 00 00 00 00 00 00 00 53 55 50 4C 41 53 55 50 4C 41 15 03 00 00 00 AA 02 00 00 08 00 ]
10:01:44.269 -> Receiv�Supla - starting initialization
10:01:46.395 -> Main storage not configured
10:01:46.428 -> Config storage not configured
10:01:46.460 -> Channel(0) value changed to NaN
10:01:46.493 -> Channel(1) value changed to NaN
10:01:46.526 -> Channel(2) value changed to -275.00
10:01:46.591 -> Channel(3) value changed to -275.00
10:01:46.624 -> Channel(4) value changed to -275.00
10:01:46.657 -> Channel(5) value changed to -275.00
10:01:46.689 -> Channel(6) value changed to -275.00
10:01:46.722 -> GUID: 9AC4341B3328445C9BA4F8FC010D8B66
10:01:46.788 -> Device name: SUPLA-ARDUINO
10:01:46.788 -> Device software version: SDK 24.02-dev
10:01:46.853 -> Initializing network layer
10:01:46.886 -> Network AP/hostname: SUPLA-ARDUINO
10:01:46.919 -> Using Supla protocol version 21
10:01:46.952 -> Current status: [5] SuplaDevice initialized
10:01:46.984 -> Enter normal mode
10:01:49.987 -> Channel(0) value changed to NaN
10:01:50.020 -> Channel(1) value changed to NaN
10:01:50.052 -> Connecting to network...
10:01:50.646 -> DHCP connection result: 1
10:01:50.679 -> localIP: 10.10.64.142
10:01:50.711 -> subnetMask: 255.255.0.0
10:01:50.745 -> gatewayIP: 10.10.0.1
10:01:50.745 -> dnsServerIP: 10.10.1.2
10:01:50.778 -> Establishing NOT encrypted connection with: svr111.supla.org (port: 2015)
10:01:50.875 -> Connected to Supla Server
10:01:50.908 -> Initializing SRPC
10:01:50.941 -> Current status: [10] Register in progress
10:01:50.974 -> CH #0, type: 9000, FuncList: 0x0, default: 0, flags: 0x0, value: [208 00 00 801 79 c0 00 19]
10:01:51.072 -> CH #1, type: 9000, FuncList: 0x0, default: 0, flags: 0x0, value: [208 00 00 801 79 c0 00 19]
10:01:51.170 -> CH #2, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:51.268 -> CH #3, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:51.367 -> CH #4, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:51.465 -> CH #5, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:51.564 -> CH #6, type: 3034, FuncList: 0x0, default: 0, flags: 0x0, value: [28 00 00 801 00 00 00 04]
10:01:51.662 -> Send: [53 55 50 4C 41 ]
10:01:54.676 -> Channel(2) value changed to 22.62
10:01:54.709 -> Channel(3) value changed to 22.40
10:01:54.741 -> Channel(4) value changed to 42.50
10:01:54.775 -> Channel(5) value changed to 0.00
10:01:54.841 -> Channel(6) value changed to 6.66
10:01:54.873 -> Recv: [53 55 50 4C 41 15 01 00 00 00 46 00 00 00 07 00 00 00 03 00 00 00 78 17 01 53 55 50 4C 41 53 55 ]
10:01:54.971 -> Device registered (activity timeout 120 s, server version: 23, server min version: 1)
10:01:55.069 -> Current status: [17] Registered and ready
10:01:55.102 -> Changing activity timeout to 30
10:01:55.135 -> Send: [53 55 50 4C 41 15 02 00 00 00 D2 00 00 00 01 00 00 00 1E ]
10:01:55.200 -> Send: [53 55 50 4C 41 ]
10:01:55.233 -> Send: [53 55 50 4C 41 15 03 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 79 C0 00 19 00 00 F8 C7 ]
10:01:55.332 -> Send: [53 55 50 4C 41 ]
10:01:58.350 -> Channel(0) value changed to 22.93
10:01:58.382 -> Channel(1) value changed to 22.81
10:01:58.448 -> Recv: [50 4C 41 15 02 00 00 00 AD 02 00 00 1B 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
10:01:58.546 -> Send: [53 55 50 4C 41 15 04 00 00 00 67 00 00 00 0E 00 00 00 01 00 00 00 00 00 79 C0 00 10 00 D0 36 40 ]
10:01:58.644 -> Send: [53 55 50 4C 41 ]
10:02:01.687 -> Recv: [00 00 00 00 00 00 00 00 00 00 00 53 55 50 4C 41 53 55 50 4C 41 15 03 00 00 00 AA 02 00 00 08 00 ]
10:02:01.793 -> Receiv�
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

Ile masz wolnego RAM'u?
Pozdrawiam
Robert Błaszczak


Moja prywatna strona: www.blaszczak.pl
cbool222
Posts: 4
Joined: Tue Mar 12, 2024 9:43 am

Post

Arduino Mega 2560 R3

Szkic używa 68400 bajtów (26%) pamięci programu. Maksimum to 253952 bajtów.
Zmienne globalne używają 4065 bajtów (49%) pamięci dynamicznej, pozostawiając 4127 bajtów dla zmiennych lokalnych. Maksimum to 8192 bajtów.
[email protected]
Posts: 1584
Joined: Mon Feb 06, 2023 8:56 am
Has thanked: 18 times
Been thanked: 26 times

Post

Z mojej walki wynika, że brakuje storage'u i nie zapisuje się konfiguracja KPOP na urządzeniu, podejrzyj sobie main.cpp tutaj:
https://github.com/rkalwak/WeatherStation/tree/testKPOP
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Obawiam się, że na chwilę obecną to na Arduino Mega nie zadziała.
KPOP wymaga klas Config, a tych nie ma zaimplementowanych dla Arduino.

Natomaist ogólnie nie powinno się crashować ani restartować.
Sprawdź jeszcze logi, czy może coś ciekawszego tam się pojawia? Jakieś info o crashu, callstack?
Najlepsze suple dla Twojego domu :mrgreen:
cbool222
Posts: 4
Joined: Tue Mar 12, 2024 9:43 am

Post

klew wrote: Thu Mar 14, 2024 10:12 am Obawiam się, że na chwilę obecną to na Arduino Mega nie zadziała.
KPOP wymaga klas Config, a tych nie ma zaimplementowanych dla Arduino.

Natomaist ogólnie nie powinno się crashować ani restartować.
Sprawdź jeszcze logi, czy może coś ciekawszego tam się pojawia? Jakieś info o crashu, callstack?
Informacje jakie Arduino wyświetla z Serial Monitora są w pierwszym poście, natomiast jeżeli masz na myśli jakieś inne logi to proszę o informacje jak je wydobyć.
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

cbool222 wrote: Thu Mar 14, 2024 10:25 am Informacje jakie Arduino wyświetla z Serial Monitora są w pierwszym poście, natomiast jeżeli masz na myśli jakieś inne logi to proszę o informacje jak je wydobyć.
Tak, widzę te logi i widzę tam dwa razy coś takiego:

Code: Select all

10:01:44.269 -> Receiv�Supla - starting initialization
Ale niestety niewiele to mówi poza tym, że coś tu poszło nie tak i urządzenie się zresetowało.
Jeśli resetuje się w kółko, to może przy którymś resecie pojawiło się więcej logów w tej okolicy?
Najlepsze suple dla Twojego domu :mrgreen:
cbool222
Posts: 4
Joined: Tue Mar 12, 2024 9:43 am

Post

klew wrote: Thu Mar 14, 2024 10:26 am
cbool222 wrote: Thu Mar 14, 2024 10:25 am Informacje jakie Arduino wyświetla z Serial Monitora są w pierwszym poście, natomiast jeżeli masz na myśli jakieś inne logi to proszę o informacje jak je wydobyć.
Tak, widzę te logi i widzę tam dwa razy coś takiego:

Code: Select all

10:01:44.269 -> Receiv�Supla - starting initialization
Ale niestety niewiele to mówi poza tym, że coś tu poszło nie tak i urządzenie się zresetowało.
Jeśli resetuje się w kółko, to może przy którymś resecie pojawiło się więcej logów w tej okolicy?
Jedyne dodatkowe info jakie się pojawia to te znakiImage
Których nie skopiowało mi tu na forum.

Teraz o dziwo nie crashuje ale Arduino cały czas jest w loopie do

Code: Select all

Recv: [00 00 00 00 00 00 00 00 00 00 00 53 55 50 4C 41 53 55 50 4C 41 15 03 00 00 00 AA 02 00 00 08 00 ]
Po tym następuje reset.

Return to “Pomoc”