Closed mczakk closed 1 year ago
Hi Matt,
actually you do not have do change anything in the code - just follow this description: https://github.com/matthias-bs/BresserWeatherSensorReceiver/blob/main/DEBUG_OUTPUT.md
(Yes, this should be added to the TTN project, too!)
Regards Matthias
ok, an update ! I now get one recieved message in the serial monitor, the code then fails as can be seen below..
16:13:35.816 -> [D][WeatherSensor.cpp:238] getMessage(): [SX1276] Receive failed: [0]
16:13:45.421 -> [V][WeatherSensor.cpp:217] getMessage(): [SX1276] Data: D4 F6 77 38 05 35 05 18 FE EE FE 10 28 02 16 90 FF F0 B7 AA 00 00 00 00 00 00 00
16:13:45.421 -> [D][WeatherSensor.cpp:219] getMessage(): [SX1276] R [D4] RSSI: -76.5
16:13:45.421 -> [V][WeatherSensor.cpp:284] findSlot(): find_slot(): ID=38053505
16:13:45.421 -> [V][WeatherSensor.cpp:338] findSlot(): find_slot(): Storing into slot #0
16:14:21.424 -> [V][WeatherSensor.cpp:217] getMessage(): [SX1276] Data: D4 4B EF 38 05 35 05 18 FF FF FF 10 28 FF 6F 69 FF 01 64 AA 00 00 00 00 00 00 00
16:14:21.424 -> [D][WeatherSensor.cpp:219] getMessage(): [SX1276] R [D4] RSSI: -77.0
16:14:21.424 -> [V][WeatherSensor.cpp:284] findSlot(): find_slot(): ID=38053505
16:14:21.424 -> [V][WeatherSensor.cpp:332] findSlot(): find_slot(): Updating slot #0
16:14:21.424 -> [D][BresserWeatherSensorTTN.ino:1075] setup(): Receiving Weather Sensor Data o.k.
16:14:21.456 -> [D][BresserWeatherSensorTTN.ino:587] setup(): mySensor.setup() - done
16:14:21.456 -> [D][BresserWeatherSensorTTN.ino:591] setup(): myLoRaWAN.setup() - done
16:14:21.456 -> [D][BresserWeatherSensorTTN.ino:1147] getVoltage(): Voltage = 284mV
16:14:21.456 -> [D][BresserWeatherSensorTTN.ino:1164] getVoltage(): Voltage = 284mV
16:14:21.489 -> [D][BresserWeatherSensorTTN.ino:1272] doUplink(): --- Uplink Data ---
16:14:21.489 -> [D][BresserWeatherSensorTTN.ino:1276] doUplink(): Air Temperature: 2.1 °C
16:14:21.489 -> [D][BresserWeatherSensorTTN.ino:1277] doUplink(): Humidity: 90 %
16:14:21.489 -> [D][BresserWeatherSensorTTN.ino:1278] doUplink(): Rain Gauge: 909.6 mm
16:14:21.489 -> [D][BresserWeatherSensorTTN.ino:1279] doUplink(): Wind Speed (avg.): 0.0 m/s
16:14:21.523 -> [D][BresserWeatherSensorTTN.ino:1280] doUplink(): Wind Speed (max.): 0.0 m/s
16:14:21.523 -> [D][BresserWeatherSensorTTN.ino:1281] doUplink(): Wind Direction: 102.0 °
16:14:21.523 -> [D][BresserWeatherSensorTTN.ino:1306] doUplink(): Supply Voltage: 284 mV
16:14:21.523 -> [D][BresserWeatherSensorTTN.ino:1309] doUplink(): Battery Voltage: 284 mV
16:14:21.523 -> [D][BresserWeatherSensorTTN.ino:1325] doUplink():
16:14:21.554 -> [D][BresserWeatherSensorTTN.ino:1414] doUplink(): Rain past 60min: 0.0 mm
16:14:21.554 -> [D][BresserWeatherSensorTTN.ino:1415] doUplink(): Rain curr. day: 0.0 mm
16:14:21.554 -> [D][BresserWeatherSensorTTN.ino:1416] doUplink(): Rain curr. week: 0.0 mm
16:14:21.554 -> [D][BresserWeatherSensorTTN.ino:1417] doUplink(): Rain curr. month: 0.0 mm
16:14:21.554 -> FAILURE
16:14:21.554 -> c:\Users\mtc20tfq\Arduino\libraries\MCCI_LoRaWAN_LMIC_library\src\lmic\lmic_us_like.c:51
as yet the esp32 has not been registered on TTN as my gateway will arrive to tomorrow, but is this error to be expected if there is no lorawan connection?
Also, my board has a jumper from spio12 to the LORA chip, as described in Ulrich's post on Hackaday: https://hackaday.io/project/186339-lora-for-bresser-5-in1-weather-station-make-iot and shown here:
I'm unsure wether this is needed, but he does use your code!!
Cheers
Matt
Hi,
yes... Another point I should add to the docs - you have to edit
Arduino/libraries/MCCI_LoRaWAN_LMIC_library/project_config/lmic_project_config.h
to set the region, e.g. for Europe:
// project-specific definitions
#define CFG_eu868 1
//#define CFG_us915 1
//#define CFG_au915 1
//#define CFG_as923 1
// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP /* for as923-JP; also define CFG_as923 */
//#define CFG_kr920 1
//#define CFG_in866 1
#define CFG_sx1276_radio 1
//#define LMIC_USE_INTERRUPTS
#define hal_init LMICHAL_init
#define LMIC_ENABLE_DeviceTimeReq 1
You can have a look if a TTN or Helium gateway is within reach: https://www.thethingsnetwork.org/map https://explorer.helium.com/
Let's see if we get the voltage measurements for your board to work. Do you know the purpose of this wire?
No, I haven't managed to connect with Ulrich to ask! I know there is no TTN within reach, as i have a TTN registered node on my desk which is not connecting. There is a Helium gateway nearby, but as i will need to connect to TTn when i replace my bresser in the field, i'm not sure if I'm going to be able to connect it to both helium and TTN?
with your amendment to Arduino/libraries/MCCI_LoRaWAN_LMIC_library/project_config/lmic_project_config.h
it now fails here!:
16:45:57.539 -> [D][BresserWeatherSensorTTN.ino:1415] doUplink(): Rain curr. day: 0.0 mm
16:45:57.539 -> [D][BresserWeatherSensorTTN.ino:1416] doUplink(): Rain curr. week: 0.0 mm
16:45:57.539 -> [D][BresserWeatherSensorTTN.ino:1417] doUplink(): Rain curr. month: 0.0 mm
16:45:57.539 -> FAILURE
16:45:57.539 -> c:\Users\mtc20tfq\Arduino\libraries\MCCI_LoRaWAN_LMIC_library\src\lmic\radio.c:1164
Edit: i removed the jumper and it still fails in with the same message
Did you see that the pin configuration has to be done in two places? https://github.com/matthias-bs/BresserWeatherSensorTTN#configure-the-rf-transceiver-gpio-wiring
Maybe this thread also helps: https://github.com/matthias-bs/BresserWeatherSensorReceiver/issues/16
lmic_project_config.h
should look like this:
// project-specific definitions
#define CFG_eu868 1
#define CFG_sx1276_radio 1
//#define LMIC_USE_INTERRUPTS
#define hal_init LMICHAL_init
#define LMIC_ENABLE_DeviceTimeReq 1
BTW: Did you check that none of the required pins is assigned for other purposes?
I followed your link :https://github.com/matthias-bs/BresserWeatherSensorTTN#configure-the-rf-transceiver-gpio-wiring
and was unsure about what to change. I have defined 'ttgo lora32' - so do i have to change the entries in weathersensor.cfg.h for that (lines 171-181?)
Not sure how i'd check other pins, I haven't assigned them knowingly!
No, the you mentioned configuration above is just fine. It is used for the sensor reception based on the BresserWeatherSensorReceiver library which in turn uses RadioLib.
Now you additionally have to modify the pin configuration to be used for LoRaWAN by BresserWeatherSensorTTN, which is based on MCCI Arduino LoRaWAN Library.
In BresserWeatherSensorTTN.ino
, you should try to make the following changes:
// Pin mapping for ESP32 (MCCI Arduino LoRaWAN Library)
// Note: Pin mapping for BresserWeatherSensorReceiver is done in WeatherSensorCfg.h!
// SPI2 is used on ESP32 per default! (e.g. see https://github.com/espressif/arduino-esp32/tree/master/variants/doitESP32devkitV1)
#if defined(ARDUINO_TTGO_LoRa32_V1)
// https://github.com/espressif/arduino-esp32/blob/master/variants/ttgo-lora32-v1/pins_arduino.h
// http://www.lilygo.cn/prod_view.aspx?TypeId=50003&Id=1130&FId=t3:50003:3
// https://github.com/Xinyuan-LilyGo/TTGO-LoRa-Series
#define PIN_LMIC_NSS LORA_CS
#define PIN_LMIC_RST LORA_RST
#define PIN_LMIC_DIO0 LORA_IRQ
#define PIN_LMIC_DIO1 cMyLoRaWAN::lmic_pinmap::LMIC_UNUSED_PIN
#define PIN_LMIC_DIO2 cMyLoRaWAN::lmic_pinmap::LMIC_UNUSED_PIN
#else
// LoRaWAN_Node board
// https://github.com/matthias-bs/LoRaWAN_Node
#define PIN_LMIC_NSS 14
#define PIN_LMIC_RST 12
#define PIN_LMIC_DIO0 4
#define PIN_LMIC_DIO1 16
#define PIN_LMIC_DIO2 17
#endif
Since the SPI configuration worked without changes for the sensor receiver, I assume it will also work out-of-the-box for the LoRaWAN transceiver.
And in BresserWeatherSensorTTNCfg.h
:
//--- Select Board ---
#ifndef ARDUINO_TTGO_LoRa32_V1
// Use pinning for LoRaWAN Node
#define LORAWAN_NODE
#endif
[...]
// ADC for supply/battery voltage measurement
// default: on-board connection to VB on FireBeetle ESP32 (with R10+R11 assembled)
// on-board connection to VBAT on TTGO LoRa32
#ifdef ADC_EN
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ADC_IN 35
#else
#define PIN_ADC_IN A0
#endif
//#define PIN_ADC_IN 34
#endif
// Additional ADC pins (default: FireBeetle ESP32)
//#define PIN_ADC0_IN A0
//#define PIN_ADC1_IN A1
//#define PIN_ADC2_IN A2
#ifdef LORAWAN_NODE
#define PIN_ADC3_IN A3
#endif
[...]
#ifdef ONEWIRE_EN
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ONEWIRE_BUS 21
#else
#define PIN_ONEWIRE_BUS 5
#endif
#endif
This sets a board specific define, avoids a conflict of GPIO5 used for the LoRa radio and the OneWire bus at the same time and hopefully selects the correct ADC input for battery voltage measurement.
There actually seems to be no connection of the supply voltage to an ADC.
ok, i think i've made the changes correctly, but now get this:
15:02:28.889 -> [D][BresserWeatherSensorTTN.ino:592] setup(): RTC sync required
15:02:28.889 -> [D][BresserWeatherSensorTTN.ino:598] setup(): myEventlog.setup() - done
15:02:28.889 -> [D][BresserWeatherSensorTTN.ino:1162] getVoltage(): Voltage = 4221mV
15:02:28.889 -> [D][WeatherSensor.cpp:81] begin(): [SX1276] Initializing ...
15:02:28.930 -> [D][WeatherSensor.cpp:94] begin(): success!
15:02:28.930 -> [D][WeatherSensor.cpp:129] begin(): [SX1276] Setup complete - awaiting incoming messages...
15:02:34.751 -> [V][WeatherSensor.cpp:217] getMessage(): [SX1276] Data: D4 02 A4 38 05 35 05 18 FF 99 FF 27 68 07 26 60 FF F0 CE AA 00 00 00 00 00 00 00
15:02:34.751 -> [D][WeatherSensor.cpp:219] getMessage(): [SX1276] R [D4] RSSI: -86.5
15:02:34.751 -> [V][WeatherSensor.cpp:284] findSlot(): find_slot(): ID=38053505
15:02:34.751 -> [V][WeatherSensor.cpp:338] findSlot(): find_slot(): Storing into slot #0
15:03:10.729 -> [V][WeatherSensor.cpp:217] getMessage(): [SX1276] Data: D4 9B BF 38 05 35 05 18 FF 88 FF 28 28 FF 6F 69 FF 01 C3 AA 00 00 00 00 00 00 00
15:03:10.762 -> [D][WeatherSensor.cpp:219] getMessage(): [SX1276] R [D4] RSSI: -87.5
15:03:10.762 -> [V][WeatherSensor.cpp:284] findSlot(): find_slot(): ID=38053505
15:03:10.762 -> [V][WeatherSensor.cpp:332] findSlot(): find_slot(): Updating slot #0
15:03:10.762 -> [D][BresserWeatherSensorTTN.ino:1090] setup(): Receiving Weather Sensor Data o.k.
15:03:10.762 -> [D][BresserWeatherSensorTTN.ino:602] setup(): mySensor.setup() - done
15:03:10.762 ->
15:03:10.762 -> c:\Users\mtc20tfq\Arduino\libraries\MCCI_LoRaWAN_LMIC_library\src\hal\hal.cpp:36
i also now have a ttn gateway, so should see if the ttgo tries to connect
O.k.
Arduino\libraries\MCCI_LoRaWAN_LMIC_library\src\hal\hal.cpp:
// NSS and DIO0 are required, DIO1 is required for LoRa, DIO2 for FSK
ASSERT(plmic_pins->nss != LMIC_UNUSED_PIN);
ASSERT(plmic_pins->dio[0] != LMIC_UNUSED_PIN);
ASSERT(plmic_pins->dio[1] != LMIC_UNUSED_PIN || plmic_pins->dio[2] != LMIC_UNUSED_PIN);
The last line is line 36. The execution stops there, because DIO1 may not be unconnected.
The problem is, there is no official definition
The only clue I currently have is this circuit diagram: https://github.com/LilyGO/TTGO-LORA32/blob/master/schematic1in6.pdf I'm not sure if this is the correct one for your board (if the photo above is your board -> yes). According to it, IO33 would be the ESP32's GPIO pin connected to the radio transceiver's DIO1 pin.
So please try this in BresserWeatherSensorTTN.ino:
// Pin mapping for ESP32 (MCCI Arduino LoRaWAN Library)
// Note: Pin mapping for BresserWeatherSensorReceiver is done in WeatherSensorCfg.h!
// SPI2 is used on ESP32 per default! (e.g. see https://github.com/espressif/arduino-esp32/tree/master/variants/doitESP32devkitV1)
#if defined(ARDUINO_TTGO_LoRa32_V1)
// https://github.com/espressif/arduino-esp32/blob/master/variants/ttgo-lora32-v1/pins_arduino.h
// http://www.lilygo.cn/prod_view.aspx?TypeId=50003&Id=1130&FId=t3:50003:3
// https://github.com/Xinyuan-LilyGo/TTGO-LoRa-Series
#define PIN_LMIC_NSS LORA_CS
#define PIN_LMIC_RST LORA_RST
#define PIN_LMIC_DIO0 LORA_IRQ
#define PIN_LMIC_DIO1 33
#define PIN_LMIC_DIO2 cMyLoRaWAN::lmic_pinmap::LMIC_UNUSED_PIN
#else
// LoRaWAN_Node board
// https://github.com/matthias-bs/LoRaWAN_Node
#define PIN_LMIC_NSS 14
#define PIN_LMIC_RST 12
#define PIN_LMIC_DIO0 4
#define PIN_LMIC_DIO1 16
#define PIN_LMIC_DIO2 17
#endif
If this does not work, you have to find out the connection otherwise - maybe you can check it with a multimeter, toggle one pin after another until you see the signal arriving at the required pin or try to google it.
Maybe this is where the red wire comes into play: If we do not know the on-board connection, we create our own... If you want to use it, you can use this:
#define PIN_LMIC_DIO1 12
Would you please do me a favor and try both variants?
is that with the wire connected?
Which antenna are you going to use? According to the circuit diagram, the large one (SMA) is connected (via R29 - 0 Ohms), while the small one (uFL) is unconnected (R28 - not assembled). You can change this if required (a solder bridge works well). Both connections should not be made at the same time (RF circuit...)
An antenna should be connected, otherwise the transmitter RF front end could be destroyed!
i'm using the antenna provided
Damn, its now failing to compile with the error :
c:\Users\mtc20tfq\Arduino\libraries\MCCI_Arduino_LoRaWAN_Library\src\lib\arduino_lorawan_sessionstate.cpp: In member function 'void Arduino_LoRaWAN::BuildSessionState(Arduino_LoRaWAN::SessionState&) const':
c:\Users\mtc20tfq\Arduino\libraries\MCCI_Arduino_LoRaWAN_Library\src\lib\arduino_lorawan_sessionstate.cpp:104:76: warning: enumeral and non-enumeral type in conditional expression [-Wextra]
constexpr unsigned maxCh = MAX_CHANNELS < State.V1.Channels.EUlike.nCh ? MAX_CHANNELS : State.V1.Channels.EUlike.nCh;
^
In file included from c:\Users\mtc20tfq\Arduino\libraries\MCCI_Arduino_LoRaWAN_Library\src\lib\arduino_lorawan_sessionstate.cpp:22:0:
c:\Users\mtc20tfq\Arduino\libraries\MCCI_Arduino_LoRaWAN_Library\src/Arduino_LoRaWAN.h: In member function 'bool Arduino_LoRaWAN::SessionChannelMask_EU_like<a_nCh, a_nBands>::setFrequency(uint8_t (&)[(nCh * 3)], unsigned int, uint32_t) [with unsigned int a_nCh = 16u; unsigned int a_nBands = 4u; uint8_t = unsigned char; uint32_t = unsigned int]':
c:\Users\mtc20tfq\Arduino\libraries\MCCI_Arduino_LoRaWAN_Library\src/Arduino_LoRaWAN.h:371:25: error: control reaches end of non-void function [-Werror=return-type]
}
^
cc1plus.exe: some warnings being treated as errors
exit status 1
Compilation error: exit status 1
I'm losing the will to live!!!
Keep cool! ;-) In the end everything gonna be alright! If not, it's not the end...
Did you apply the fixed mentioned in this section? https://github.com/matthias-bs/BresserWeatherSensorTTN#software-build-setup
Yes, I re downloaded all the files and tried again with verbose debugging off. It seems that it was treating warnings as errors and not compiling. I think I just need to sort out the payload formatter now!
To be clear, you should fix these mentioned bugs as described: https://github.com/mcci-catena/arduino-lorawan/pull/204 https://github.com/mcci-catena/arduino-lmic/issues/714#issuecomment-822051171
Yes, I re downloaded all the files and tried again with verbose debugging off. It seems that it was treating warnings as errors and not compiling. I think I just need to sort out the payload formatter now!
Does that mean the code seems to work now? With which pin config?
is that with the wire connected?
Yes, the red wire is the connection between the radio module pin 10 (DIO1) and the ESP32 GPIO pin 12.
Using
With the wire connected. "To be clear, you should fix these mentioned bugs as described: mcci-catena/arduino-lorawan#204 mcci-catena/arduino-lmic#714 (comment)" Ill do these tomorrow! Thanks for your help Matthias 😁😁
as far as i can see the two fixes are done in the current code, I've uploaded the payload formatter to ttn. The code seems to complie and upload fine, this is the output from serial monitor:
12:23:22.543 -> �[V][Preferences.cpp:341] getUChar(): nvs_get_u8 fail: ws_timeout NOT_FOUND
12:23:23.043 -> [D][BresserWeatherSensorTTN.ino:573] setup(): Preferences: weathersensor_timeout: 180 s
12:23:23.043 -> [V][Preferences.cpp:365] getUShort(): nvs_get_u16 fail: sleep_interval NOT_FOUND
12:23:23.043 -> [D][BresserWeatherSensorTTN.ino:575] setup(): Preferences: sleep_interval: 360 s
12:23:23.043 -> [V][Preferences.cpp:365] getUShort(): nvs_get_u16 fail: sleep_interval_long NOT_FOUND
12:23:23.076 -> [D][BresserWeatherSensorTTN.ino:577] setup(): Preferences: sleep_interval_long: 900 s
12:23:23.076 -> [D][BresserWeatherSensorTTN.ino:582] setup():
12:23:23.076 -> [D][BresserWeatherSensorTTN.ino:955] printDateTime(): 1970-01-01 00:00:00
12:23:23.076 -> [D][BresserWeatherSensorTTN.ino:590] setup(): RTC sync required
12:23:23.076 -> [D][BresserWeatherSensorTTN.ino:596] setup(): myEventlog.setup() - done
12:23:23.117 -> [D][BresserWeatherSensorTTN.ino:1160] getVoltage(): Voltage = 4071mV
12:23:23.117 -> [D][WeatherSensor.cpp:81] begin(): [SX1276] Initializing ...
12:23:23.117 -> [D][WeatherSensor.cpp:94] begin(): success!
12:23:23.117 -> [D][WeatherSensor.cpp:129] begin(): [SX1276] Setup complete - awaiting incoming messages...
12:23:24.410 -> [V][WeatherSensor.cpp:217] getMessage(): [SX1276] Data: D4 C6 DB 38 05 35 05 18 FF FF FF 21 68 00 96 96 FF F0 CF AA 00 00 00 00 00 00 00
12:23:24.410 -> [D][WeatherSensor.cpp:219] getMessage(): [SX1276] R [D4] RSSI: -75.5
12:23:24.410 -> [V][WeatherSensor.cpp:284] findSlot(): find_slot(): ID=38053505
12:23:24.410 -> [V][WeatherSensor.cpp:338] findSlot(): find_slot(): Storing into slot #0
12:23:36.394 -> [V][WeatherSensor.cpp:217] getMessage(): [SX1276] Data: D4 C0 13 38 05 35 05 18 FF FF FF 21 68 FF 6F 69 FF 01 13 AA 00 00 00 00 00 00 00
12:23:36.394 -> [D][WeatherSensor.cpp:219] getMessage(): [SX1276] R [D4] RSSI: -74.0
12:23:36.394 -> [V][WeatherSensor.cpp:284] findSlot(): find_slot(): ID=38053505
12:23:36.394 -> [V][WeatherSensor.cpp:332] findSlot(): find_slot(): Updating slot #0
12:23:36.394 -> [D][BresserWeatherSensorTTN.ino:1088] setup(): Receiving Weather Sensor Data o.k.
12:23:36.427 -> [D][BresserWeatherSensorTTN.ino:600] setup(): mySensor.setup() - done
12:23:36.427 -> [D][BresserWeatherSensorTTN.ino:895] NetGetSessionState(): failed
12:23:36.427 -> [D][BresserWeatherSensorTTN.ino:604] setup(): myLoRaWAN.setup() - done
12:23:36.427 -> [D][BresserWeatherSensorTTN.ino:1160] getVoltage(): Voltage = 4626mV
12:23:36.427 -> [D][BresserWeatherSensorTTN.ino:1177] getVoltage(): Voltage = 335mV
12:23:36.459 -> [D][BresserWeatherSensorTTN.ino:1285] doUplink(): --- Uplink Data ---
12:23:36.459 -> [D][BresserWeatherSensorTTN.ino:1289] doUplink(): Air Temperature: 0.9 °C
12:23:36.459 -> [D][BresserWeatherSensorTTN.ino:1290] doUplink(): Humidity: 96 %
12:23:36.459 -> [D][BresserWeatherSensorTTN.ino:1291] doUplink(): Rain Gauge: 909.6 mm
12:23:36.459 -> [D][BresserWeatherSensorTTN.ino:1292] doUplink(): Wind Speed (avg.): 0.0 m/s
12:23:36.494 -> [D][BresserWeatherSensorTTN.ino:1293] doUplink(): Wind Speed (max.): 0.0 m/s
12:23:36.494 -> [D][BresserWeatherSensorTTN.ino:1294] doUplink(): Wind Direction: 216.0 °
12:23:36.494 -> [D][BresserWeatherSensorTTN.ino:1319] doUplink(): Supply Voltage: 4626 mV
12:23:36.494 -> [D][BresserWeatherSensorTTN.ino:1322] doUplink(): Battery Voltage: 335 mV
12:23:36.494 -> [D][BresserWeatherSensorTTN.ino:1338] doUplink():
12:23:36.527 -> [D][BresserWeatherSensorTTN.ino:1427] doUplink(): Rain past 60min: 0.0 mm
12:23:36.527 -> [D][BresserWeatherSensorTTN.ino:1428] doUplink(): Rain curr. day: 0.0 mm
12:23:36.527 -> [D][BresserWeatherSensorTTN.ino:1429] doUplink(): Rain curr. week: 0.0 mm
12:23:36.527 -> [D][BresserWeatherSensorTTN.ino:1430] doUplink(): Rain curr. month: 0.0 mm
12:23:36.527 -> [D][BresserWeatherSensorTTN.ino:881] NetSaveSessionState():
12:23:36.560 -> [V][BresserWeatherSensorTTN.ino:837] printSessionState(): Tag: 1
12:23:36.560 -> [V][BresserWeatherSensorTTN.ino:838] printSessionState(): Size: 216
12:23:36.560 -> [V][BresserWeatherSensorTTN.ino:839] printSessionState(): Region: 1
12:23:36.560 -> [V][BresserWeatherSensorTTN.ino:840] printSessionState(): LinkDR: 5
12:23:36.560 -> [V][BresserWeatherSensorTTN.ino:841] printSessionState(): FCntUp: 0
12:23:36.560 -> [V][BresserWeatherSensorTTN.ino:842] printSessionState(): FCntDown: 0
12:23:36.594 -> [V][BresserWeatherSensorTTN.ino:843] printSessionState(): gpsTime: 0
12:23:36.594 -> [V][BresserWeatherSensorTTN.ino:844] printSessionState(): globalAvail: -877103
12:23:36.594 -> [V][BresserWeatherSensorTTN.ino:845] printSessionState(): Rx2Frequency: 869525000
12:23:36.594 -> [V][BresserWeatherSensorTTN.ino:846] printSessionState(): PingFrequency: 869525000
12:23:36.594 -> [V][BresserWeatherSensorTTN.ino:847] printSessionState(): Country: 0
12:23:36.627 -> [V][BresserWeatherSensorTTN.ino:848] printSessionState(): LinkIntegrity: 0
12:23:36.627 -> [D][BresserWeatherSensorTTN.ino:868] NetSaveSessionInfo():
12:23:36.627 -> [V][BresserWeatherSensorTTN.ino:809] printSessionInfo(): Tag: 2
12:23:36.627 -> [V][BresserWeatherSensorTTN.ino:810] printSessionInfo(): Size: 52
12:23:36.627 -> [V][BresserWeatherSensorTTN.ino:811] printSessionInfo(): Rsv2: 0
12:23:36.660 -> [V][BresserWeatherSensorTTN.ino:812] printSessionInfo(): Rsv3: 0
12:23:36.660 -> [V][BresserWeatherSensorTTN.ino:813] printSessionInfo(): NetID: 0x00000000
12:23:36.660 -> [V][BresserWeatherSensorTTN.ino:814] printSessionInfo(): DevAddr: 0x00000000
12:23:36.660 -> [V][BresserWeatherSensorTTN.ino:821] printSessionInfo(): NwkSKey: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
12:23:36.660 -> [V][BresserWeatherSensorTTN.ino:829] printSessionInfo(): AppSKey: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
12:23:36.694 -> [D][BresserWeatherSensorTTN.ino:881] NetSaveSessionState():
12:23:36.694 -> [V][BresserWeatherSensorTTN.ino:837] printSessionState(): Tag: 1
12:23:36.694 -> [V][BresserWeatherSensorTTN.ino:838] printSessionState(): Size: 216
12:23:36.694 -> [V][BresserWeatherSensorTTN.ino:839] printSessionState(): Region: 1
12:23:36.694 -> [V][BresserWeatherSensorTTN.ino:840] printSessionState(): LinkDR: 5
12:23:36.727 -> [V][BresserWeatherSensorTTN.ino:841] printSessionState(): FCntUp: 0
12:23:36.727 -> [V][BresserWeatherSensorTTN.ino:842] printSessionState(): FCntDown: 0
12:23:36.727 -> [V][BresserWeatherSensorTTN.ino:843] printSessionState(): gpsTime: 0
12:23:36.727 -> [V][BresserWeatherSensorTTN.ino:844] printSessionState(): globalAvail: -886088
12:23:36.727 -> [V][BresserWeatherSensorTTN.ino:845] printSessionState(): Rx2Frequency: 869525000
12:23:36.769 -> [V][BresserWeatherSensorTTN.ino:846] printSessionState(): PingFrequency: 869525000
12:23:36.769 -> [V][BresserWeatherSensorTTN.ino:847] printSessionState(): Country: 0
12:23:36.769 -> [V][BresserWeatherSensorTTN.ino:848] printSessionState(): LinkIntegrity: 0
12:23:47.101 -> 18282 ms:[I][BresserWeatherSensorTTN.ino:754] operator()(): TX @18282 ms: ch=0 rps=0x01 (SF7 BW125 CR 4/5 Crc IH=0)
12:23:47.101 ->
12:24:58.725 -> 89900 ms:[I][BresserWeatherSensorTTN.ino:754] operator()(): TX @89900 ms: ch=1 rps=0x01 (SF7 BW125 CR 4/5 Crc IH=0)
12:24:58.725 ->
12:26:09.875 -> 161067 ms:[I][BresserWeatherSensorTTN.ino:754] operator()(): TX @161067 ms: ch=2 rps=0x01 (SF7 BW125 CR 4/5 Crc IH=0)
12:26:09.875 ->
12:27:19.620 -> 230742 ms:[I][BresserWeatherSensorTTN.ino:754] operator()(): TX @230742 ms: ch=1 rps=0x02 (SF8 BW125 CR 4/5 Crc IH=0)
12:27:19.620 ->
12:29:23.093 -> [D][BresserWeatherSensorTTN.ino:1232] doUplink(): busy
12:29:26.719 -> 357849 ms:[I][BresserWeatherSensorTTN.ino:754] operator()(): TX @357849 ms: ch=2 rps=0x02 (SF8 BW125 CR 4/5 Crc IH=0)
12:29:26.719 ->
if i leave it it just repeats the last line and there is no messages recieved on ttn
Did you configure your secrets.h
with the same values as in the network provider's console?
e.g.:
#define SECRETS
// deveui, little-endian
static const std::uint8_t deveui[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
// appeui, little-endian
static const std::uint8_t appeui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// appkey: just a string of bytes, sometimes referred to as "big endian".
static const std::uint8_t appkey[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 };
Besides, this looks good! Normally you have to wait a while (several minutes for a public network is quite normal) until the node has joined the network. After the first join, the connection details are saved and the next join will be much faster (~2...3 minutes).
And the supply voltage measurement seems to be valid, too.
as far as i know, yes:
as far as the join goes, I have a gateway on my desk, which is connected, and anither lorawan node which connects to it successfully, so i'm guessing that there is something in my code which is not allowing the join. Whetther it is my ttn settings or the esp32 code is a mystery to me though!
I think you have to reverse deveui[] and appeui[]. ;-)
I checked your patches, and my code is the same apart from 'ttn.ino' #define PIN_LMIC_DIO1 33 i had 12, but have changed it to 33 and the position of the //--- Select Board --- in 'ttncfg.h' which i have moved. Unsure what you mean by 'reverse deveui[] and appeui[]?
static const std::uint8_t deveui[] = { 0xE7, 0x99, 0x05, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
static const std::uint8_t appeui[] = { 0xE7, 0x99, 0x05, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
IT'S WORKING!!!!
how did you know to reverse the app and dev eui??
now getting messages onto ttn, but the decode fails with 'error: mask length is 42 whereas input is 34 at decode (
Excellent!!! I can assure you, that I stumbled through some (if not most) of those pitfalls before...
If you are just transmitting the weather sensor data, you have to configure ttn_decoder_fp.js as follows:
return decode(
bytes,
[bitmap, temperature, uint8, uint16fp1, uint16fp1, uint16fp1,
rawfloat
],
['status', 'air_temp_c', 'humidity', 'wind_gust_meter_sec', 'wind_avg_meter_sec', 'wind_direction_deg',
'rain_mm'
]
);
The upper array contains the data types ant the lower one the names of the JSON elements, i.e. the second element is air_temp_c
and has the temperature
type (2 bytes) and starts at the second byte of the array (because the preceding status
is the first byte.
The size of the data types is:
Which features did you disable in WeatherSensorTTNCfg.h?
this is 'ttncfg.h'
//--- Select LoRaWAN Network ---
// The Things Network
#define ARDUINO_LMIC_CFG_NETWORK_TTN 1
// Helium Network
// see mcci-cathena/arduino-lorawan issue #185 "Add Helium EU868 support"
// (https://github.com/mcci-catena/arduino-lorawan/issues/185)
//#define ARDUINO_LMIC_CFG_NETWORK_GENERIC 0
// Enable LORAWAN debug mode - this generates dummy weather data and skips weather sensor reception
//#define LORAWAN_DEBUG
// Battery voltage thresholds for energy saving
// If SLEEP_EN is defined and battery voltage is below BATTERY_WEAK [mV], MCU will sleep for SLEEP_INTERVAL_LONG
#define BATTERY_WEAK 3500
// Go to sleep mode immediately after start if battery voltage is below BATTERY_LOW [mV]
#define BATTERY_LOW 3200
// Enable sleep mode - sleep after successful transmission to TTN (recommended!)
#define SLEEP_EN
// If SLEEP_EN is defined, MCU will sleep for SLEEP_INTERVAL seconds after succesful transmission
#define SLEEP_INTERVAL 300
// Long sleep interval, MCU will sleep for SLEEP_INTERVAL_LONG seconds if battery voltage is below BATTERY_WEAK
#define SLEEP_INTERVAL_LONG 900
// RTC to network time sync interval (in minutes)
#define CLOCK_SYNC_INTERVAL 24 * 60
// Force deep sleep after a certain time, even if transmission was not completed
#define FORCE_SLEEP
// Force a new join procedure (instead of re-join) after encountering sleep timeout
#define FORCE_JOIN_AFTER_SLEEP_TIMEOUT
// During initialization (not joined), force deep sleep after SLEEP_TIMEOUT_INITIAL (if enabled)
#define SLEEP_TIMEOUT_INITIAL 1800
// If already joined, force deep sleep after SLEEP_TIMEOUT_JOINED seconds (if enabled)
#define SLEEP_TIMEOUT_JOINED 600
// Additional timeout to be applied after joining if Network Time Request pending
#define SLEEP_TIMEOUT_EXTRA 300
// Timeout for weather sensor data reception (seconds)
#define WEATHERSENSOR_TIMEOUT 180
// If enabled, enter deep sleep mode if receiving weather sensor data was not successful
//#define WEATHERSENSOR_DATA_REQUIRED
// Enable transmission of weather sensor ID
#define SENSORID_EN
// Enable rain data statistics
#define RAINDATA_EN
// Enable battery / supply voltage measurement
#define ADC_EN
// Enable OneWire temperature measurement
//#define ONEWIRE_EN
// Enable BLE temperature/humidity measurement
// Note: BLE requires a lot of program memory!
//#define MITHERMOMETER_EN
// Enable Bresser Soil Temperature/Moisture Sensor
//#define SOILSENSOR_EN
I will try adding the decode to decoder_fp.js
O.k., you just have to compare the enabled decoder.write...() calls starting from https://github.com/matthias-bs/BresserWeatherSensorTTN/blob/a4f39623f8f51a334d56202e9e24164aa880c1f3/BresserWeatherSensorTTN.ino#L1345 to the decode() function in ttn_decoder_fp.js.
still failing!
Sensor ID has 32 bits, i.e. the first entry should be uint32 (not uint8)!
And with ADC_EN enabled, you should get the voltage (in mV, uint16) after rain_mm
.
Thanks, I'll try again tomorrow!
Still struggling to be honest 🙁 What does line 4 of ttn_decoder_fp.js refer to? And is this important? As I don't know where src/decoder.js is!
Sorry, you can ignore that comment. You can copy the entire contents of the script into the TTN decoder text input field and replace any previous contents. Just the decoder() function has to be adapted as described. I will propose a solution tomorrow.
If I got your configuration correctly, the following decoder should work for you: https://github.com/matthias-bs/BresserWeatherSensorTTN/blob/main/decoder_basic.js
Just paste it into the TTN console in the tab 'payload formatters'/'uplink' and hit 'save changes'
still getting the same error, I notice that line 126 is commenyed out and line 130 is active, and i have not defined MiThermo? is there a way to show the length of the generated message in 'ttn.ino' ?
O.k., you mean in the *.js for the status bits. Don't worry, that won't make any problems.
With "Core Debug Level: Info" (or Debug/Verbose) set in the Arduino IDE:
this->m_fBusy = true;
log_i("Payload length: %d", encoder.getLength());
// Schedule transmission
if (! myLoRaWAN.SendBuffer(
[...]
this confirms that my payload length is 38 how do i generate those extra 4 bytes? or tell the .js to expect only 38?
there's no 'sensor_ID' in the 'uplink data' output on the serial monitor, could this be the missing 4 bytes?
Hmmm, I feel a little bit like blindfolded...
There is the following section in the sketch:
#ifdef SENSORID_EN
if (ws > -1) {
encoder.writeUint32(weatherSensor.sensor[ws].sensor_id);
} else {
encoder.writeUint32(0);
}
#endif
So if SENSORID_EN is defined, the ID is present in the payload, but you're right - there is no debug output for it.
Do you know your sensor's ID from the previous tests? Could you please share the undecoded payload? Or again your BresserSensorTTNCfg.h?
You could also try to add encoder.writeUint32(0xFFFFFFFF);
to your sketch. If you try different positions in the code, you will finally find the one where something was missing, because anything else will be decoded correctly.
the undecoded payload from ttn? 053505380301C25008000800500A6766634427125B0100000000000000000000000000000000 i also tried adding this line at ttn.ino:1295
DEBUG_PRINTF("sensor_id: %1.1f", weatherSensor.sensor[ws].sensor_id);
but it didn't sem to work!
ttncfg.h:
///////////////////////////////////////////////////////////////////////////////
// BresserWeatherSensorTTNCfg.h
//
// User specific configuration for BresserWeatherSensorTTN.ino
//
// - Enabling or disabling of features
// - Voltage thresholds for power saving
// - Timing configuration
// - Timezone
//
// created: 08/2022
//
//
// MIT License
//
// Copyright (c) 2022 Matthias Prinke
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//
// History:
//
// 20220819 Created from BresserWeatherSensorTTN.ino
// 20221011 Changed timezone handling
// 20221113 Fixed ADC defines
// 20221117 Enabled FORCE_JOIN_AFTER_SLEEP_TIMEOUT per default
// Added defines for power saving -
// BATTERY_WEAK, BATTERY_LOW, SLEEP_INTERVAL_LONG
// 20221228 Modified DEBUG_PRINTF/DEBUG_PRINTF_TS macros to use
// Arduino logging functions
// 20221230 Added WEATHERSENSOR_DATA_REQUIRED
// 20220112 Removed LMIC_ENABLE_DeviceTimeReq; must be defined in
// ~/Arduino/libraries/MCCI_LoRaWAN_LMIC_library/project_config/
// lmic_project_config.h
// in order to be recognized!!!
//
// ToDo:
// -
//
///////////////////////////////////////////////////////////////////////////////
#include <vector>
#include <string>
// Enable debug mode (debug messages via serial port)
// Arduino IDE: Tools->Core Debug Level: "Debug|Verbose"
#define CORE_DEBUG_LEVEL ARDUHAL_LOG_LEVEL_DEBUG
//#define CORE_DEBUG_LEVEL ARDUHAL_LOG_LEVEL_VERBOSE
//--- Select Board ---
#ifndef ARDUINO_TTGO_LoRa32_V1
// Use pinning for LoRaWAN Node
#define LORAWAN_NODE
#endif
//--- Select LoRaWAN Network ---
// The Things Network
#define ARDUINO_LMIC_CFG_NETWORK_TTN 1
// Helium Network
// see mcci-cathena/arduino-lorawan issue #185 "Add Helium EU868 support"
// (https://github.com/mcci-catena/arduino-lorawan/issues/185)
//#define ARDUINO_LMIC_CFG_NETWORK_GENERIC 0
// Enable LORAWAN debug mode - this generates dummy weather data and skips weather sensor reception
//#define LORAWAN_DEBUG
// Battery voltage thresholds for energy saving
// If SLEEP_EN is defined and battery voltage is below BATTERY_WEAK [mV], MCU will sleep for SLEEP_INTERVAL_LONG
#define BATTERY_WEAK 3500
// Go to sleep mode immediately after start if battery voltage is below BATTERY_LOW [mV]
#define BATTERY_LOW 3200
// Enable sleep mode - sleep after successful transmission to TTN (recommended!)
#define SLEEP_EN
// If SLEEP_EN is defined, MCU will sleep for SLEEP_INTERVAL seconds after succesful transmission
#define SLEEP_INTERVAL 300
// Long sleep interval, MCU will sleep for SLEEP_INTERVAL_LONG seconds if battery voltage is below BATTERY_WEAK
#define SLEEP_INTERVAL_LONG 900
// RTC to network time sync interval (in minutes)
#define CLOCK_SYNC_INTERVAL 24 * 60
// Force deep sleep after a certain time, even if transmission was not completed
#define FORCE_SLEEP
// Force a new join procedure (instead of re-join) after encountering sleep timeout
#define FORCE_JOIN_AFTER_SLEEP_TIMEOUT
// During initialization (not joined), force deep sleep after SLEEP_TIMEOUT_INITIAL (if enabled)
#define SLEEP_TIMEOUT_INITIAL 1800
// If already joined, force deep sleep after SLEEP_TIMEOUT_JOINED seconds (if enabled)
#define SLEEP_TIMEOUT_JOINED 600
// Additional timeout to be applied after joining if Network Time Request pending
#define SLEEP_TIMEOUT_EXTRA 300
// Timeout for weather sensor data reception (seconds)
#define WEATHERSENSOR_TIMEOUT 180
// If enabled, enter deep sleep mode if receiving weather sensor data was not successful
//#define WEATHERSENSOR_DATA_REQUIRED
// Enable transmission of weather sensor ID
#define SENSORID_EN
// Enable rain data statistics
#define RAINDATA_EN
// Enable battery / supply voltage measurement
#define ADC_EN
// Enable OneWire temperature measurement
//#define ONEWIRE_EN
// Enable BLE temperature/humidity measurement
// Note: BLE requires a lot of program memory!
//#define MITHERMOMETER_EN
// Enable Bresser Soil Temperature/Moisture Sensor
//#define SOILSENSOR_EN
// ADC for supply/battery voltage measurement
// default: on-board connection to VB on FireBeetle ESP32 (with R10+R11 assembled)
// on-board connection to VBAT on TTGO LoRa32
#ifdef ADC_EN
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ADC_IN 35
#else
#define PIN_ADC_IN A0
#endif
//#define PIN_ADC_IN 34
#endif
// Additional ADC pins (default: FireBeetle ESP32)
//#define PIN_ADC0_IN A0
//#define PIN_ADC1_IN A1
//#define PIN_ADC2_IN A2
#ifdef LORAWAN_NODE
#define PIN_ADC3_IN A3
#endif
// Additional ADC pins (default: FireBeetle ESP32)
//#define PIN_ADC0_IN A0
//#define PIN_ADC1_IN A1
//#define PIN_ADC2_IN A2
#define PIN_ADC3_IN A3
#ifdef PIN_ADC0_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC0_DIV = 0.5;
const uint8_t ADC0_SAMPLES = 10;
#endif
#ifdef PIN_ADC1_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC1_DIV = 0.5;
const uint8_t ADC1_SAMPLES = 10;
#endif
#ifdef PIN_ADC2_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC2_DIV = 0.5;
const uint8_t ADC2_SAMPLES = 10;
#endif
#ifdef PIN_ADC3_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC3_DIV = 0.5;
const uint8_t ADC3_SAMPLES = 10;
#endif
#ifdef ONEWIRE_EN
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ONEWIRE_BUS 21
#else
#define PIN_ONEWIRE_BUS 5
#endif
#endif
#ifdef ADC_EN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float UBATT_DIV = 0.5;
const uint8_t UBATT_SAMPLES = 10;
#endif
#ifdef MITHERMOMETER_EN
// BLE scan time in seconds
const int bleScanTime = 10;
// List of known sensors' BLE addresses
std::vector<std::string> knownBLEAddresses = {"a4:c1:38:b8:1f:7f"};
#endif
// Enter your time zone (https://remotemonitoringsystems.ca/time-zone-abbreviations.php)
const char* TZ_INFO = "GMT+0BST-1,M3.5.0/01:00:00,M10.5.0/02:00:00";
You could change BresserWeatherSensorTTNCfg.h as follows:
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ADC3_IN 34
#else
#define PIN_ADC3_IN A3
#endif
You can then use my default config and decoder. Any missing sensors/input signals should then just generate some default values.
DEBUG_PRINTF("sensor_id: %1.1f", weatherSensor.sensor[ws].sensor_id);
Should be:
log_i("sensor_id: %u", weatherSensor.sensor[ws].sensor_id);
I don't now if DEBUG_PRINTF is still usable (needs a define) and the format string %f is for floating point, while %u is for unsigned integers.
hmmm, tried your .cfg change and bettery readings were very low (294mV) so it went to sleep immediately! changed the battery weak and battery low thresholds and trying again! (also added log_i line :)
Hi Matthias - me again! I have complied and uploaded this code to my esp32 (TTGO LoRa32-OLED V1 with
defined, but am not seeing anything in the serial monitor. how can i check that the board is recieving the data from the bresser?
Cheers Matt