Coder Social home page Coder Social logo

Comments (93)

mczakk avatar mczakk commented on September 26, 2024 1

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 (:145:15:(21))
i guess this is a setting in the ttn_decoder_fp.js file?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024 1

ok, hold the front page, i may have made a very noobie error....
I think i was updating the application payload formatter, not the end device one !
i now get this on ttn :)
sucess

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024 1

I owe you a debt of gratitude Sir!!

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024 1

D'oh, forgot to tell the Node-red mqtt in node to output parsed Jason!
All is good now, just have to get the data into aws now 😱🤣😂🤣

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024 1

What is the subject of your project?

I'm developing a model to predict how much rainfall gets through forest canopies to become groundwater (and later floodwater) so I have off grid weather stations and rainfall gauges connecting via iot. My weather station was connected to a pi and a gateway in an enclosure in a forest, but the enclosure leaked, and the pi was pulling to much current. That's why I've moved to the esp32. It should be going live next week, thanks in no small part to you!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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:
9474801660490556559
I'm unsure wether this is needed, but he does use your code!!

Cheers

Matt

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

You can have a look if a TTN or Helium gateway is within reach:
https://www.thethingsnetwork.org/map
https://explorer.helium.com/

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Let's see if we get the voltage measurements for your board to work.
Do you know the purpose of this wire?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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:
matthias-bs/BresserWeatherSensorReceiver#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

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

BTW: Did you check that none of the required pins is assigned for other purposes?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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?)
cfg
Not sure how i'd check other pins, I haven't assigned them knowingly!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

is that with the wire connected?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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!

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

i'm using the antenna provided

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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!!!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

To be clear, you should fix these mentioned bugs as described:
mcci-catena/arduino-lorawan#204
mcci-catena/arduino-lmic#714 (comment)

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

Using
#define PIN_LMIC_DIO1 12
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 😁😁

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

as far as i know, yes:
ttn
secrets
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!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

I think you have to reverse deveui[] and appeui[]. ;-)

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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[]?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024
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 };

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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:

  • bitmap: 1 byte
  • uint8: 1 byte
  • uint16/uint16fp1: 2 bytes
  • temperature: 2 bytes
  • rawfloat: 4 bytes

Which features did you disable in WeatherSensorTTNCfg.h?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

O.k., you just have to compare the enabled decoder.write...() calls starting from

LoraEncoder encoder(loraData);
to the decode() function in ttn_decoder_fp.js.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

still failing!
matt

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

Thanks, I'll try again tomorrow!

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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'

Screenshot_20230122_141728

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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' ?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

O.k., you mean in the *.js for the status bits. Don't worry, that won't make any problems.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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(
    [...]

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

this confirms that my payload length is 38
how do i generate those extra 4 bytes?
or tell the .js to expect only 38?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

there's no 'sensor_ID' in the 'uplink data' output on the serial monitor,
could this be the missing 4 bytes?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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";  

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

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 :)

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Here is something unexpected:

// 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

I did not expect PIN_ADC3_IN to be defined, but this would give us only two extra bytes.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

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 :)

Ah, o.k.:

#define BATTERY_LOW 0

We'll come back to this later.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

Here is something unexpected:

// 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

I did not expect PIN_ADC3_IN to be defined, but this would give us only two extra bytes.

trying with

// 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

btw, got sensor_id :

14:55:12.551 -> [D][BresserWeatherSensorTTN.ino:1295] doUplink(): sensor_id: 939865349

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

With both ADC voltages enabled:

    return decode(
      bytes,
      [uint32,        bitmap,          temperature,     uint8,       uint16fp1,             uint16fp1,            uint16fp1,
       rawfloat,      uint16,          uint16,          rawfloat,    rawfloat,              rawfloat,             rawfloat
      ],
      ['id',          'status',        'air_temp_c',    'humidity',  'wind_gust_meter_sec', 'wind_avg_meter_sec', 'wind_direction_deg',
       'rain_mm',     'supply_v',      'battery_v',     'rain_hr',   'rain_day',            'rain_week',          'rain_mon'
      ]
    );

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Your payload:
>05350538< 0301C25008000800500A6766634427125B0100000000000000000000000000000000
Your sensor ID converted to hex: 0x38053505

So, you have the ID in your payload (bytes reversed).

Next byte:
05350538 >03< 01C25008000800500A6766634427125B0100000000000000000000000000000000
return ['res2', 'res1', 'res0', 'ble_ok', 's1_dec_ok', 's1_batt_ok', 'ws_dec_ok', 'ws_batt_ok']
Binary: 00000011
Weather Station decoding o.k. & battery o.k. - that's fine!

Next two bytes (temperature):
05350538 >01C2< 5008000800500A6766634427125B0100000000000000000000000000000000
(ignoring it for now)

Next byte (humidity):
05350538 01C2 >50< 08000800500A6766634427125B0100000000000000000000000000000000
0x50 = 80% rel. humidity (o.k.?)

wind gust (two bytes):
05350538 01C250>0800< 0800500A6766634427125B0100000000000000000000000000000000
0.8 m/s?

wind avg (two bytes):
05350538 01C2500800 >0800< 500A6766634427125B0100000000000000000000000000000000

wind direction (two bytes):
05350538 01C25008000800 >500A< 6766634427125B0100000000000000000000000000000000
0x0A50 = 264.0°?

rain gauge (4 bytes, floating point):
05350538 01C25008000800500A >67666344< 27125B0100000000000000000000000000000000
(ignoring it for now)

supply voltage (two bytes):
05350538 01C25008000800500A67666344 >2712< 5B0100000000000000000000000000000000
0x1227 = 4647 mV

battery voltage (two bytes):
05350538 01C25008000800500A676663442712 >5B01< 00000000000000000000000000000000
0x015B = 347 mV

remaining: rain statistics, 4x 4 bytes, all zero:
05350538 01C25008000800500A6766634427125B01 >00000000< >00000000< >00000000< >00000000<

So, I'd say there is nothing wrong with your payload.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

commenting out //#define PIN_ADC3_IN A3 resulten in ttn error changing to '36 at decode' from '38 at decode' as you suggested.
trying with #define PIN_ADC3_IN A3 and change to 'decode.js' now

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

both battery readings showing now, but message length in monitor output still 38 !!
is it possible to see the message in serial monitor?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

I know there is probably an obvious answer to this, but this bit of 'decoder.js' concerns me?
I dont have 'soil_sensor' or 'MiThermo' defined?

 var i = bytesToInt(byte);
    var bm = ('00000000' + Number(i).toString(2)).substr(-8).split('').map(Number).map(Boolean);
    // Only Weather Sensor
    //return ['res5', 'res4', 'res3', 'res2', 'res1', 'res0', 'dec_ok', 'batt_ok']
    // Weather Sensor + MiThermo (BLE) Sensor
    //return ['res4', 'res3', 'res2', 'res1', 'res0', 'ble_ok', 'dec_ok', 'batt_ok']
    // Weather Sensor, Soil Sensor and MiThermo (BLE) Sensor
    return ['res2', 'res1', 'res0', 'ble_ok', 's1_dec_ok', 's1_batt_ok', 'ws_dec_ok', 'ws_batt_ok']
        .reduce(function(obj, pos, index) {
        obj[pos] = bm[index];
        return obj;
        }, {});

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

This function decodes the status byte, i.e. extracts all bit positions and assign their value to a named bit in the status object, e.g.:

"status": {
            "ble_ok": true,
            "long_sleep": false,
            "rtc_sync_req": false,
            "runtime_expired": true,
            "s1_batt_ok": true,
            "s1_dec_ok": true,
            "ws_batt_ok": true,
            "ws_dec_ok": true
          }

So in the worst case, some wrong values are interpreted here. In The best case, the default values are zero and the decoded values make sense.

(You see we have some undocumented features...)

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

where is that function?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

In the Arduino sketch:

    // Status flags
    encoder.writeBitmap(longSleep,
                        rtcSyncReq, 
                        runtimeExpired,
                        mithermometer_valid,
                        (s1 > -1) ? weatherSensor.sensor[s1].valid : false,
                        (s1 > -1) ? weatherSensor.sensor[s1].battery_ok : false,
                        (ws > -1) ? weatherSensor.sensor[ws].valid : false,
                        (ws > -1) ? weatherSensor.sensor[ws].battery_ok : false);

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Congratulations!

The only this which needs improvement is the handling of supply voltage vs battery voltage. I'll set up a new issue as a reminder, but I think it's not urgent.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

My status decoder:

    var bitmap = function(byte) {
    if (byte.length !== bitmap.BYTES) {
        throw new Error('Bitmap must have exactly 1 byte');
    }
    var i = bytesToInt(byte);
    var bm = ('00000000' + Number(i).toString(2)).substr(-8).split('').map(Number).map(Boolean);
    return ['res', 'rtc_sync_req', 'runtime_expired', 'ble_ok', 's1_dec_ok', 's1_batt_ok', 'ws_dec_ok', 'ws_batt_ok']
        .reduce(function(obj, pos, index) {
        obj[pos] = bm[index];
        return obj;
        }, {});
    };
    bitmap.BYTES = 1;

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

If you have a decent multimeter, it would be great to have a current measurement for this board in deep sleep mode. For this, we need the current drawn from the battery input, not the USB port. In fact, the USB may not be connected for this.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

aaaarg, i'm getting the mqtt out of ttn, but it doesn't show the wind!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

???
But it's in your decoded output according to the screenshot! If you mean an MQTT client: maybe the topic names are too long? You can change them in the decoder, of course.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

I've used the ttn mqtt integration to publish the mqtt message, and am subscribing with node-red.
the mqtt i recieve is truncated at 's1_dec_ok'
(see attached .txt)
ttn-nodered-output.txt
i tried taking out the bitmap and 'status' decoder, but this just threw the decode out!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Maybe there is a way to increase a buffer size for MQTT messages in node-red? The JSON string from TTN is quite big!

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

what are the topic names in the decoder, maybe i can just subscribe to the topics i need?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Presumably, you only need "decoded_payload".

I'm always using https://mqtt-explorer.com/ for debugging.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

just trying mqtt decoder, can't get past the 'up' topic, and nodered mqtt in node wont accept v3/bresserttn@ttn/devices/bresseresp32/up
or v3/bresserttn@ttn/devices/bresseresp32/up/# as a topic :(
giving up for the day i think!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Cool! Mission completed!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Some interesting information/discussion regarding the TTGO LoRa32 board:
LilyGO/TTGO-LORA32#3

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

Cool! Mission completed!

For you, maybe! For which I and my PhD project are eternally grateful! 😁🙏😁.

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

What is the subject of your project?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

⁹Good luck!

From what I've read, the TTGO LoRa32 is not optimal regarding standby (deep sleep) current consumption and LoRaWAN range.

You might consider https://github.com/matthias-bs/LoRaWAN_Node if any of this proves to be a concern.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

We have developed our own lora node for the rain gauges, and hopefully the ttgo will work.
It would be interesting if you could have a chat with myself and my network guy about the project. Can we connect via zoom? Do you have twitter to exchange contact details?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

Hi again, unfortunately it seems we have another issue :(
the payload formatter seems to output the temperature, wind and rain values as strings, is it possible to output them as floats?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

That is easy: just replace return f.toFixed(1); by return f; (other variables accordingly)

The reason for this was that I cannot set the number of decimals in my MQTT panel and therefore converted it in the decoder to a string with one decimal. The MQTT panel does not care it it's a string or a float.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

that seems to have changed them to 'int' - no decimal places, can we make it a float?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

From the oldest version I kept:

    var uint16fp1 = function(bytes) {
    if (bytes.length !== uint16.BYTES) {
        throw new Error('int must have exactly 2 bytes');
    }
    return bytesToInt(bytes) * 0.1;
    };
    uint16fp1.BYTES = 2;

It seems I snipped the previous example from rawfloat.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

hmm, at line 37?
has no effect!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

Please check this version: https://github.com/matthias-bs/BresserWeatherSensorTTN/blob/21a5de1b01874a554f31626768fac11cc6cd7853/decoder_basic.js

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

copied that code into ttn. tested it and it gives :


  "bytes": {
    "air_temp_c": 4.8,
    "humidity": 87,
    "id": 939865349,
    "rain_day": 0,
    "rain_hr": 3.9796876386824805e-43,
    "rain_mm": 910,
    "rain_mon": 0,
    "rain_week": 0,
    "status": {
      "ble_ok": false,
"res0": false,
      "res1": false,
      "res2": false,
      "s1_batt_ok": false,
      "s1_dec_ok": false,
      "ws_batt_ok": true,
      "ws_dec_ok": true
    },
    "supply_v": 284,
    "wind_avg_meter_sec": 0,
    "wind_direction_deg": 186,
    "wind_gust_meter_sec": 0

so still no decimals for wind or rain, and a seemingly random value for rain_hr_mm!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

It's up to the application how to display floating point numbers. If the value is 0, it might well display it as 0 instead of 0.0.
air_temp_c is now shown as 4.8 (no quotation marks, i.e. it's shown as floating point), but it could also be shown as 4.799999999 if the internal representation would lead to this result.
Accordingly, rain_hr could be correct - a very small number, almost zero but not exactly zero.

https://stackoverflow.com/questions/19554972/json-standard-floating-point-numbers
https://stackoverflow.com/questions/35709595/why-would-you-use-a-string-in-json-to-represent-a-decimal-number

So apparently, you can not have both a machine readable floating point value and a nice, human-friendly display.

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

Unfortunately i think there is a bit of an issue with the decoder! I decided to test the device by adding a little water to the rain counter, I made it tip four times. the 'rain_mm' value went from 910.0mm to 910,7999 (perfectly normal), the others ......
air_temp_c: 2.5
humidity: 93
id: 939865349
rain_day: -33619248
rain_hr: -107481312
rain_mm: 910.7999877929688
rain_mon: -33619248
rain_week: -33619248
status: object
supply_v: 284
wind_avg_meter_sec: 0
wind_direction_deg: 354
wind_gust_meter_sec: 0

not sure whats going on here!, maybe you can shed a little light?

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

We have developed our own lora node for the rain gauges, and hopefully the ttgo will work. It would be interesting if you could have a chat with myself and my network guy about the project. Can we connect via zoom? Do you have twitter to exchange contact details?

I do not have Twitter, but chances are that you can find me on LinkedIn. Or is there a way to start a private conversation in GitHub? For sure I can join a zoom call if you set up one. Maybe on Friday?

from bresserweathersensorttn.

mczakk avatar mczakk commented on September 26, 2024

I don't think you can pm on github, I'll find you on linkedin. Friday might be difficult, hopefully I'll be installing the esp32 in the field!

from bresserweathersensorttn.

matthias-bs avatar matthias-bs commented on September 26, 2024

wire

Finally I found the purpose of this wire: Big ESP32 + SX127x topic part 2 has an excellent section about the different versions of the TTGO LoRa32 OLED boards. According to this, V2 lacks an on-board connection between the ESP and the LoRa radio chip!

In general, the version numbering/documentation of these boards is confusing and a schematic is not even available for most of them.

from bresserweathersensorttn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.