matthias-bs / Bresser_Weather_Sensor_CC1101_MQTT

Bresser 5-in-1/6-in-1 868 MHz Weather Sensor Radio Receiver based on CC1101 and ESP32/ESP8266 - provides data via secure MQTT [deprecated]
MIT License
4 stars 2 forks source link

not all data in mqtt-message #1

Closed smudiii closed 2 years ago

smudiii commented 2 years ago

Hi, I'm using your code on a ESP8266. Works great so far. I own a Bresser 5-in-1 Art-N°: 9602510 (new one), which uses the same protocol as a Bresser 6-in-1. In MQTT i only get a message without rain-data although rain-data is received by CC1101:

20:18:22.920 -> [CC1101] Data: D4 A0 47 97 65 15 33 18 FF FF FF 10 68 22 26 46 FF F0 B1 AA 00 00 00 00 00 00 00 20:18:22.986 -> [CC1101] R [0xD4] RSSI: -42.000000 LQI: 0 20:18:22.986 -> decode_ok: 1, temp_ok: 1, wind_ok: 1, rain_ok: 0 20:18:22.986 -> Id: [97651533] Battery: [OK ] Ch: [0] Temp: [22.2C] Hum: [ 46%] Wind max: [0.0m/s] Wind avg: [0.0m/s] Wind dir: [106.0deg] Rain: [-----.-mm] 20:18:22.986 -> {"sensor_id": 97651533,"ch:":0,"battery_ok":1,"temp_c":22.2,"humidity":46,"wind_gust":0.0,"wind_avg":0.0,"wind_gust_bft":0,"wind_avg_bft":0,"wind_dir":106.0} 20:18:34.962 -> [CC1101] Data: D4 B0 43 97 65 15 33 18 FF FF FF 10 68 FF FE B7 FF 01 7A AA 00 00 00 00 00 00 00 20:18:34.962 -> [CC1101] R [0xD4] RSSI: -41.000000 LQI: 0 20:18:34.962 -> decode_ok: 1, temp_ok: 0, wind_ok: 1, rain_ok: 1 20:18:34.962 -> Id: [97651533] Battery: [OK ] Ch: [0] Temp: [---.-C] Hum: [---] Wind max: [0.0m/s] Wind avg: [0.0m/s] Wind dir: [106.0deg] Rain: [ 14.8mm] 20:18:37.483 -> [CC1101] Receive failed - failed, code 0

MQTT message: { "sensor_id": 97651533, "ch:": 0, "battery_ok": 1, "temp_c": 22.2, "humidity": 46, "wind_gust": 0, "wind_avg": 0, "wind_gust_bft": 0, "wind_avg_bft": 0, "wind_dir": 106 }

sometimes (esp reset) i got rain-data but no temp and humi:

20:08:58.990 -> decode_ok: 1, temp_ok: 0, wind_ok: 1, rain_ok: 1 20:08:58.990 -> Id: [97651533] Battery: [OK ] Ch: [0] Temp: [---.-C] Hum: [---] Wind max: [0.0m/s] Wind avg: [0.0m/s] Wind dir: [106.0deg] Rain: [ 14.8mm] 20:08:58.990 -> {"sensor_id": 97651533,"ch:":0,"battery_ok":1,"wind_gust":0.0,"wind_avg":0.0,"wind_gust_bft":0,"wind_avg_bft":0,"wind_dir":106.0,"rain":14.8} 20:08:58.990 -> {"rssi":-43.5,"lqi":0} 20:09:10.101 -> [CC1101] Receive failed - failed, code 0 20:09:10.931 -> [CC1101] Data: D4 A0 47 97 65 15 33 18 FF FF FF 10 68 22 26 46 FF F0 B1 AA 00 00 00 00 00 00 00 20:09:10.963 -> [CC1101] R [0xD4] RSSI: -43.000000 LQI: 0 20:09:10.963 -> decode_ok: 1, temp_ok: 1, wind_ok: 1, rain_ok: 0 20:09:10.963 -> Id: [97651533] Battery: [OK ] Ch: [0] Temp: [22.2C] Hum: [ 46%] Wind max: [0.0m/s] Wind avg: [0.0m/s] Wind dir: [106.0deg] Rain: [-----.-mm] 20:09:14.414 -> [CC1101] Receive failed - failed, code 0

MQTT message: { "sensor_id": 97651533, "ch:": 0, "battery_ok": 1, "wind_gust": 0, "wind_avg": 0, "wind_gust_bft": 0, "wind_avg_bft": 0, "wind_dir": 106, "rain": 14.8 }

Any help is appreciated. thx

matthias-bs commented 2 years ago

Hi,

the Bresser 6-in-1 protocol provides temperature/humidity and rain gauge data in different messages in an alternating fashion. Reception of sensor messages and transmission of MQTT frames is done asynchronously in Bresser_Weather_Sensor_CC1101_MQTT.

With the current implementation, the MQTT message only provides the contents of the last sensor message and makes no attempt to collect data from multiple sensor messages.

However, when sleep mode is enabled, it is tried to receive all sensor data before going to sleep. (see Bresser_Weather_Sensor_CC1101_MQTT.ino line 1012ff.)

If you prefer to have a complete set of data (even if part of it may be a little bit out-of-date due to reception problems), you could use the flags temp_ok/rain_ok (which aggregates the state; see line 966f) instead of weatherData->temp_ok/rain_ok (which reflects the state of the last message only) to determine which part of the MQTT data to send and reset these flags afterwards.

However, you might want to wait until I add an MQTT example to my all-new BresserWeatherSensorLib!

See BresserWeatherSensorLib/tree/main/examples/BresserWeatherSensorWaiting line 71:

    // Attempt to receive entire data set with timeout of 30s
    // Try to receive complete set of data, even if data is distributed 
    // across multiple radio messages.
    bool decode_ok = weatherSensor.getData(30000, true /* complete*/);

Please note that I could not test BresserWeatherSensorLib yet.

Cheers, Matthias

matthias-bs commented 2 years ago

Could you please try BresserWeatherSensorLib/blob/main/examples/BresserWeatherSensorMQTT/BresserWeatherSensorMQTT.ino?

smudiii commented 2 years ago

Hi, i got the following error:

bresser_new:202:46: error: 'PIN_RECEIVER_IRQ' was not declared in this scope; did you mean 'PIN_RECEIVER_DIO1'? 202 | WeatherSensor weatherSensor(PIN_RECEIVER_CS, PIN_RECEIVER_IRQ, PIN_RECEIVER_RESET, PIN_RECEIVER_GPIO); | ^~~~ | PIN_RECEIVER_DIO1 bresser_new:202:84: error: 'PIN_RECEIVER_GPIO' was not declared in this scope; did you mean 'PIN_RECEIVER_GDO2'? 202 | WeatherSensor weatherSensor(PIN_RECEIVER_CS, PIN_RECEIVER_IRQ, PIN_RECEIVER_RESET, PIN_RECEIVER_GPIO); | ^~~~~ | PIN_RECEIVER_GDO2 /home/smu/Arduino/bresser_new/bresser_new.ino: In function 'void loop()': bresser_new:471:74: error: no matching function for call to 'WeatherSensor::getData(int, bool, void (*)())' 471 | decode_ok = weatherSensor.getData(30000, true, &clientLoopWrapper); | ^ In file included from /home/smu/Arduino/bresser_new/bresser_new.ino:111: /home/smu/Arduino/bresser_new/WeatherSensor.h:109:17: note: candidate: 'uint8_t WeatherSensor::getData(unsigned int, bool)' 109 | uint8_t getData(unsigned timeout, bool complete = false); | ^~~ /home/smu/Arduino/bresser_new/WeatherSensor.h:109:17: note: candidate expects 2 arguments, 3 provided exit status 1 'PIN_RECEIVER_IRQ' was not declared in this scope; did you mean 'PIN_RECEIVER_DIO1'?

matthias-bs commented 2 years ago

Hi, I have done some fixes. Could you please try again? Please change BresserWeatherSensorLib/blob/main/examples/BresserWeatherSensorMQTT/WeatherSensorCfg.h as required. Cheers, Matthias

smudiii commented 2 years ago

Hi, got the following error while compiling:

/home/smu/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: sketch/bresser_new.ino.cpp.o: in function_Z10mqtt_setupv': /home/smu/Arduino/bresser_new/bresser_new.ino:234: undefined reference to _ZN13WeatherSensor5beginEv' /home/smu/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: sketch/bresser_new.ino.cpp.o: in function_ZN14HardwareSerial5beginEm': /home/smu/Arduino/libraries/arduino-mqtt-master/src/MQTTClient.h:103: undefined reference to _ZN13WeatherSensor5beginEv' /home/smu/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: sketch/bresser_new.ino.cpp.o:(.text.loop+0x2c): undefined reference to_ZN13WeatherSensor7getDataEjbPFvvE' /home/smu/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: sketch/bresser_new.ino.cpp.o: in function loop': /home/smu/Arduino/bresser_new/bresser_new.ino:421: undefined reference to_ZN13WeatherSensor7getDataEjbPFvvE' collect2: error: ld returned 1 exit status exit status 1 Fehler beim Kompilieren für das Board Generic ESP8266 Module. ` Grüße

matthias-bs commented 2 years ago

Hi, Hmmm... That's a linker error. Maybe it helps to delete objects from a previous compiler run from /tmp/arduino-build-*.

I tried to compile from scratch with the following steps (Arduino 1.8.18/ESP8266 Board Support Package 3.0.2):

  1. Downloaded https://github.com/matthias-bs/BresserWeatherSensorLib/archive/refs/tags/v0.0.2.zip
  2. Installed the library above in the Arduino GUI ("Sketch->Bibliothek einbinden->.ZIP-Bibliothek hinzufügen")
  3. Copied secrets.h to ~/Arduino/libraries/BresserWeatherSensorLib-0.0.2/examples/BresserWeatherSensorMQTT/
  4. Opened ~/Arduino/libraries/BresserWeatherSensorLib-0.0.2/examples/BresserWeatherSensorMQTT/BresserWeatherSensorMQTT.ino in the Arduino GUI
  5. The first compile attempt failed, because WeatherSensorCfg.h cannot be found while including it in BresserWeatherSensorLib-0.0.2/src/WeatherSensor.h (even if it is in BresserWeatherSensorLib-0.0.2/examples/BresserWeatherSensorMQTT) - as a workaraound, copy it to the src/ directory, too.
  6. Now compiling worked fine

I will try to find a solution for the problem in step #5. WeatherSensorCfg.hshould be modified for the sketch and therefore not be saved in the library path. Currently, it has to be included both in the sketch and in the library.

I'm not sure if this helps to solve your problem, though.

Cheers, Matthias

matthias-bs commented 2 years ago

As another workaround to step #5 above, copy all files to the sketch directory BresserWeatherSensorMQTT:

BresserWeatherSensorMQTT.ino
secrets.h
WeatherSensorCfg.h
WeatherSensor.cpp
WeatherSensor.h
smudiii commented 2 years ago

Now it works like a charm! Great work, thanks a lot.

matthias-bs commented 2 years ago

Phew! That message made my day! Which way did you go? Any suggestions how to handle the file WeatherSensorCfg.hproperly?

matthias-bs commented 2 years ago

The solution to the original problem (see https://github.com/matthias-bs/Bresser_Weather_Sensor_CC1101_MQTT/issues/1#issuecomment-1140422224 for an explanation) is provided in BresserWeatherSensorLib.

smudiii commented 2 years ago

tried this:

Hi, Hmmm... That's a linker error. Maybe it helps to delete objects from a previous compiler run from /tmp/arduino-build-*.

I tried to compile from scratch with the following steps (Arduino 1.8.18/ESP8266 Board Support Package 3.0.2):

1. Downloaded https://github.com/matthias-bs/BresserWeatherSensorLib/archive/refs/tags/v0.0.2.zip

2. Installed the library above in the Arduino GUI ("Sketch->Bibliothek einbinden->.ZIP-Bibliothek hinzufügen")

3. Copied `secrets.h` to `~/Arduino/libraries/BresserWeatherSensorLib-0.0.2/examples/BresserWeatherSensorMQTT/`

4. Opened `~/Arduino/libraries/BresserWeatherSensorLib-0.0.2/examples/BresserWeatherSensorMQTT/BresserWeatherSensorMQTT.ino` in the Arduino GUI

5. The first compile attempt failed, because `WeatherSensorCfg.h` cannot be found while including it in `BresserWeatherSensorLib-0.0.2/src/WeatherSensor.h` (even if it is in `BresserWeatherSensorLib-0.0.2/examples/BresserWeatherSensorMQTT`) - as a workaraound, copy it to the `src/` directory, too.

6. Now compiling worked fine

I will try to find a solution for the problem in step #5. WeatherSensorCfg.hshould be modified for the sketch and therefore not be saved in the library path. Currently, it has to be included both in the sketch and in the library.

I'm not sure if this helps to solve your problem, though.

Cheers, Matthias

i think because you reference to WeatherSensorCfg.h in WeatherSensor.h this file must be at both places.