CongducPham / WaterSense

WaterSense project
5 stars 10 forks source link

How to connect sensor node to a gateway #1

Open mtuchi opened 5 years ago

mtuchi commented 5 years ago

Hello @CongducPham, Am trying out to use waziup for soil moisture monitoring so far i have hit a deadlock on connecting the sensor to communicate with the gateway.

View serial monitor logs ``` LoRa soil moisture sensor, extended version Arduino Pro Mini detected Unrecognized transceiver ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... LoRa soil moisture sensor, extended version Arduino Pro Mini detected SX1276 detected, starting SX1276 LF/HF calibration ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... Setting Mode: state 0 Setting Channel: state 0 Setting Power: state 0 Setting node addr: state 0 SX1272 successfully configured SM1 on 10 sample is 1022 SM2 on 10 sample is 248 Sending \!SM1/1022/SM2/248 Real payload size is 18 \!SM1/1022/SM2/248 plain payload hex 05 06 07 08 5C 21 53 4D 31 2F 31 30 32 32 2F 53 4D 32 2F 32 34 38 Encrypting encrypted payload D5 20 B0 26 E0 63 87 FD 58 2E 75 62 BA 90 86 81 1F B4 E4 12 96 B9 calculate MIC with NwkSKey transmitted LoRaWAN-like packet: MHDR[1] | DevAddr[4] | FCtrl[1] | FCnt[2] | FPort[1] | EncryptedPayload | MIC[4] 40 02 00 00 00 00 00 00 01 D5 20 B0 26 E0 63 87 FD 58 2E 75 62 BA 90 86 81 1F B4 E4 12 96 B9 D4 DF ED 52 end-device uses encapsulated LoRaWAN packet format only for encryption --> CAD duration 0 ###1 --> waiting for 1 DIFS (DIFS=3SIFS) = 549 --> retry --> CAD duration 2 ###1 --> waiting for 1 DIFS (DIFS=3SIFS) = 549 --> retry --> CAD duration 2 ###1 --> waiting for 3 DIFS (DIFS=3SIFS) = 1647 --> retry --> CAD duration 2 ###1 --> waiting for 7 DIFS (DIFS=3SIFS) = 3843 --> retry --> CAD duration 2 ###1 --> waiting for 7 DIFS (DIFS=3SIFS) = 3843 --> retry --> CAD duration 0 ###1 --> waiting for 7 DIFS (DIFS=3SIFS) = 3843 --> retry --> CAD duration 0 ###1 --> waiting for 3 DIFS (DIFS=3SIFS) = 1647 --> retry --> CAD duration 0 ###1 --> waiting for 2 DIFS (DIFS=3SIFS) = 1098 --> retry --> CAD duration 0 ###1 --> waiting for 2 DIFS (DIFS=3SIFS) = 1098 --> retry --> CAD duration 0 ###1 --> waiting for 2 DIFS (DIFS=3SIFS) = 1098 --> retry --> CAD duration 0 ###1 --> waiting for 7 DIFS (DIFS=3SIFS) = 3843 --> retry --> CAD duration 2 ###1 --> waiting for 3 DIFS (DIFS=3SIFS) = 1647 --> retry --> CAD duration 2 ###1 --> waiting for 1 DIFS (DIFS=3SIFS) = 549 --> retry --> CAD duration 0 ###1 --> waiting for 7 DIFS (DIFS=3SIFS) = 3843 --> retry --> CAD duration 2 ###1 --> waiting for 1 DIFS (DIFS=3SIFS) = 549 --> retry --> CAD duration 0 ###1 --> waiting for 6 DIFS (DIFS=3SIFS) = 3294 --> retry --> CAD duration 2 ###1 --> waiting for 3 DIFS (DIFS=3SIFS) = 1647 --> retry --> CAD duration 2 ###1 --> waiting for 5 DIFS (DIFS=3SIFS) = 2745 --> retry --> CAD duration 2 ###1 --> waiting for 5 DIFS (DIFS=3SIFS) = 2745 --> retry --> CAD duration 2 ###1 --> waiting for 4 DIFS (DIFS=3SIFS) = 2196 --> retry --> CAD duration 3 ###1 --> waiting for 5 DIFS (DIFS=3SIFS) = 2745 --> retry --> CAD duration 0 ###1 --> waiting for 6 DIFS (DIFS=3SIFS) = 3294 --> retry --> CAD duration 0 ###1 --> waiting for 2 DIFS (DIFS=3SIFS) = 1098 --> retry --> CAD duration 0 ###1 --> waiting for 1 DIFS (DIFS=3SIFS) = 549 --> retry --> CAD duration 2 ###1 --> waiting for 2 DIFS (DIFS=3SIFS) = 1098 --> retry --> CAD duration 2 ###1 --> waiting for 4 DIFS (DIFS=3SIFS) = 2196 --> retry --> CAD duration 2 ###1 --> waiting for 7 DIFS (DIFS=3SIFS) = 3843 --> retry --> CAD duration 0 ###1 --> waiting for 3 DIFS (DIFS=3SIFS) = 1647 --> retry --> CAD duration 0 ###1 --> waiting for 1 DIFS (DIFS=3SIFS) = 549 --> retry --> CAD duration 2 ###1 --> waiting for 3 DIFS (DIFS=3SIFS) = 1647 --> retry --> CAD duration 2 ```

My sensor node setup

Am using a Arduino Pro Mini with the free PCB boards that was provided in the LowCostLoraGW repo, with the soldered radio module RF95W

img_20190216_141458

My gateway setup

Raspeberry pi 3, radio module is RF95W, I have followed the tutorial on setting up the gateway, So everything is up to date, PABOOST is enabled

img_20190216_141508

screen shot 2019-02-16 at 14 36 47

Gateway troubleshoot

I still can not see the gateway on the dashboard (Maybe because i have made it private). But am not sure why it's not showing. Also on troubleshooting the gateway i got the following logs

View gateway logs ``` pi@raspberrypi:~/lora_gateway $ pi@raspberrypi:~/lora_gateway $ sudo ./lora_gateway SX1276 detected, starting. SX1276 LF/HF calibration ... ^$**********Power ON: state 0 ^$Default sync word: 0x12 ^$LoRa mode 1 ^$Setting mode: state 0 ^$Channel CH_10_868: state 0 ^$Use PA_BOOST amplifier line ^$Set LoRa power dBm to 14 ^$Power: state 0 ^$Get Preamble Length: state 0 ^$Preamble Length: 8 ^$LoRa addr 1: state 0 ^$SX1272/76 configured as LR-BS. Waiting RF input for transparent RF-serial bridge ^$Low-level gw status ON ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 5 ^$Receive error 5 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ^$Receive error 1 ```

Help of any kinda will be much appreciated

CongducPham commented 5 years ago

I think that you have problem with your radio module or antenna. Are you sure it is an antenna for 868MHz? check also the connection plug of the antenna.

mtuchi commented 5 years ago

I think that you have problem with your radio module or antenna. Are you sure it is an antenna for 868MHz? check also the connection plug of the antenna.

How do i confirm if it's the antenna for 868MHz ?

mtuchi commented 5 years ago

Hello @CongducPham I have made some progress in troubleshooting the problem now looks like my sensor node is sending data here is the serial monitor logs

LoRa soil moisture sensor, extended version
Arduino Pro Mini detected
SX1276 detected, starting
SX1276 LF/HF calibration
...
Get back previous sx1272 config
Using packet sequence number of 9
Setting Mode: state 0
Setting Channel: state 0
Setting Power: state 0
Setting node addr: state 0
SX1272 successfully configured
SM1 on 10 sample is 246
SM2 on 10 sample is 241
Sending \!SM1/246/SM2/241
Real payload size is 17
\!SM1/246/SM2/241
plain payload hex
05 06 07 08 5C 21 53 4D 31 2F 32 34 36 2F 53 4D 32 2F 32 34 31 
Encrypting
encrypted payload
D5 20 B0 26 E0 63 87 FD 58 2E 76 66 BE 8D FA 9F 60 A9 F9 14 93 
calculate MIC with NwkSKey
transmitted LoRaWAN-like packet:
MHDR[1] | DevAddr[4] | FCtrl[1] | FCnt[2] | FPort[1] | EncryptedPayload | MIC[4]
40 02 00 00 00 00 00 00 01 D5 20 B0 26 E0 63 87 FD 58 2E 76 66 BE 8D FA 9F 60 A9 F9 14 93 D8 65 5E 95 
end-device uses encapsulated LoRaWAN packet format only for encryption
--> CAD duration 549
OK1
--> waiting for 1 CAD = 62
--> CAD duration 549
OK2
LoRa pkt size 34
LoRa pkt seq 9
LoRa Sent in 2220
LoRa Sent w/CAD in 2769
Packet sent, state 0
Switch to power saving mode
Successfully switch LoRa module in sleep mode
..

But my gateway is not receiving the data from the sensor or it does receive but doesn't send to the cloud. Here is my gateway logs

Following last lines of ../Dropbox/LoRa-test/post-processing.log. CTRL-C to return
Current UTC date is
Thu Feb 21 08:49:49 UTC 2019
2019-02-21T09:48:14.267312> 2019-02-21 09:48:14.228077
2019-02-21T09:48:14.267889> post status: gw ON
2019-02-21T09:48:14.268412> post status: executing periodic tasks
2019-02-21T09:48:14.477540> post status: start running
2019-02-21T09:48:14.481268> post status: show current GPS position
2019-02-21T09:48:14.481875> post status show GPS: current GPS coordinate: gw lat 39.285884 long -6.817607
2019-02-21T09:48:14.482447> post status: exiting
2019-02-21T09:48:15.229956>
2019-02-21T09:48:15.230415> Current working directory: /home/pi/lora_gateway
2019-02-21T09:48:15.230760> SX1276 detected, starting.
2019-02-21T09:48:15.231084> SX1276 LF/HF calibration
2019-02-21T09:48:15.231398> ...
2019-02-21T09:48:15.231710> **********Power ON: state 0
2019-02-21T09:48:15.232024> Default sync word: 0x12
2019-02-21T09:48:15.232333> LoRa mode 1
2019-02-21T09:48:15.232639> Setting mode: state 0
2019-02-21T09:48:15.232960> Frequency 865.200000: state 0
2019-02-21T09:48:15.233354> Use PA_BOOST amplifier line
2019-02-21T09:48:15.233696> Set LoRa power dBm to 14
2019-02-21T09:48:15.234008> Power: state 0
2019-02-21T09:48:15.234322> Get Preamble Length: state 0
2019-02-21T09:48:15.234648> Preamble Length: 8
2019-02-21T09:48:15.234982> LoRa addr 1: state 0
2019-02-21T09:48:15.235322> SX1272/76 configured as LR-BS. Waiting RF input for transparent RF-serial bridge
2019-02-21T09:48:15.584036> Low-level gw status ON
2019-02-21T09:49:55.814416> --- rxlora. dst=1 type=0x16 src=2 seq=9 len=0 SNR=-19 RSSIpkt=-127 BW=125 CR=4/5 SF=12
2019-02-21T09:49:55.814988> 2019-02-21T09:49:55.814105
2019-02-21T09:49:55.815345> rcv ctrl pkt info (^p): 1,22,2,9,0,-19,-127
2019-02-21T09:49:55.815724> splitted in:  [1, 22, 2, 9, 0, -19, -127]
2019-02-21T09:49:55.816105> (dst=1 type=0x16(DATA WAPPKEY ENCRYPTED) src=2 seq=9 len=0 SNR=-19 RSSI=-127)
2019-02-21T09:49:55.816514> rcv ctrl radio info (^r): 125,5,12
2019-02-21T09:49:55.816895> splitted in:  [125, 5, 12]
2019-02-21T09:49:55.817264> (BW=125 CR=5 SF=12)
2019-02-21T09:49:55.817631> rcv timestamp (^t): 2019-02-21T09:49:55.811
2019-02-21T09:49:55.818003>
2019-02-21T09:49:55.818343> got first framing byte
2019-02-21T09:49:55.818696> --> got LoRa data prefix
2019-02-21T09:49:55.819058> --> DATA encrypted: encrypted payload size is 0
2019-02-21T09:49:55.819416> --> DATA encrypted: local decryption not activated
2019-02-21T09:49:55.819846> --> FYI base64 of encrypted frame w/MIC:
2019-02-21T09:49:55.820181> --> number of enabled clouds is 0
2019-02-21T09:49:55.820511> --> discard encrypted data
2019-02-21T09:49:55.820836>

I have enabled all clouds but still doesn't send the data to clouds

CongducPham commented 5 years ago

It is because you have encryption on the device but didn't enable decryption on the gateway. The simplest thing to do is to disable encryption on the device by commenting the WITH_AES line on the device and flash again.

mtuchi commented 5 years ago

It is because you have encryption on the device but didn't enable decryption on the gateway. The simplest thing to do is to disable encryption on the device by commenting the WITH_AES line on the device and flash again.

After commenting the WITH_AES, The new gateway logs doesn't seems to be sending data to the clouds

Following last lines of ../Dropbox/LoRa-test/post-processing.log. CTRL-C to return
Current UTC date is
Thu Feb 21 09:17:04 UTC 2019
2019-02-21T10:15:02.085171> 2019-02-21 10:15:02.033190
2019-02-21T10:15:02.085622> post status: gw ON
2019-02-21T10:15:02.086088> post status: executing periodic tasks
2019-02-21T10:15:02.297257> post status: start running
2019-02-21T10:15:02.297976> post status: show current GPS position
2019-02-21T10:15:02.298548> post status show GPS: current GPS coordinate: gw lat 39.285884 long -6.817607
2019-02-21T10:15:02.299037> post status: exiting
2019-02-21T10:15:03.034930>
2019-02-21T10:15:03.035438> Current working directory: /home/pi/lora_gateway
2019-02-21T10:15:03.035817> SX1276 detected, starting.
2019-02-21T10:15:03.036159> SX1276 LF/HF calibration
2019-02-21T10:15:03.036492> ...
2019-02-21T10:15:03.036870> **********Power ON: state 0
2019-02-21T10:15:03.037310> Default sync word: 0x12
2019-02-21T10:15:03.037671> LoRa mode 1
2019-02-21T10:15:03.037992> Setting mode: state 0
2019-02-21T10:15:03.038315> Frequency 865.200000: state 0
2019-02-21T10:15:03.038643> Use PA_BOOST amplifier line
2019-02-21T10:15:03.038972> Set LoRa power dBm to 14
2019-02-21T10:15:03.039316> Power: state 0
2019-02-21T10:15:03.039644> Get Preamble Length: state 0
2019-02-21T10:15:03.040257> Preamble Length: 8
2019-02-21T10:15:03.040708> LoRa addr 1: state 0
2019-02-21T10:15:03.041102> SX1272/76 configured as LR-BS. Waiting RF input for transparent RF-serial bridge
2019-02-21T10:15:03.996088> Low-level gw status ON
2019-02-21T10:17:40.157323> --- rxlora. dst=1 type=0x12 src=2 seq=12 len=0 SNR=-21 RSSIpkt=-129 BW=125 CR=4/5 SF=12
2019-02-21T10:17:40.158139> 2019-02-21T10:17:40.157021
2019-02-21T10:17:40.158645> rcv ctrl pkt info (^p): 1,18,2,12,0,-21,-129
2019-02-21T10:17:40.159090> splitted in:  [1, 18, 2, 12, 0, -21, -129]
2019-02-21T10:17:40.159508> (dst=1 type=0x12(DATA WAPPKEY) src=2 seq=12 len=0 SNR=-21 RSSI=-129)
2019-02-21T10:17:40.160063> rcv ctrl radio info (^r): 125,5,12
2019-02-21T10:17:40.160485> splitted in:  [125, 5, 12]
2019-02-21T10:17:40.161300> (BW=125 CR=5 SF=12)
2019-02-21T10:17:40.161855> rcv timestamp (^t): 2019-02-21T10:17:40.154
2019-02-21T10:17:40.162406>
CongducPham commented 5 years ago

I don’t see why it is not uploading. Please provide clouds.json file. Besides at the device, uncomment PABOOST.

mtuchi commented 5 years ago

I don’t see why it is not uploading. Please provide clouds.json file. Besides at the device, uncomment PABOOST.

Yes i have uncomment PABOOST in device, it's just the gateway now, it's not sending the data it receives

BEGIN OUTPUT
Showing clouds.json
{
  "clouds": [
    {
      "name": "Local gateway MongoDB",
      "notice": "do not remove the MongoDB cloud declaration, just change enabled and max_months_to_store if needed",
      "script": "python CloudMongoDB.py",
      "type": "database",
      "max_months_to_store": 2,
      "enabled": true
    },
    {
      "name": "SMS Service",
      "script": "python CloudSMS.py",
      "type": "smsservice",
      "enabled": true,
      "always_enabled": false
    },
    {
      "name": "Temporary storage for no Internet connection",
      "script": "python CloudNoInternet.py",
      "type": "file",
      "enabled": true
    },
    {
      "name": "WAZIUP SMS Service ",
      "script": "python CloudWAZIUP_SMS.py",
      "type": "smsservice",
      "enabled": true,
      "always_enabled": false
    },
    {
      "name": "WAZIUP Orion cloud new API",
      "script": "python CloudWAZIUP.py",
      "type": "iotcloud",
      "enabled": true
    },
    {
      "name": "WAZIUP Orion cloud old API",
      "script": "python CloudOrion.py",
      "type": "iotcloud",
      "enabled": false
    },
    {
      "name": "ThingSpeak cloud",
      "script": "python CloudThingSpeak.py",
      "type": "iotcloud",
      "enabled": true
    },
    {
      "name": "NodeRed flow",
      "script": "python CloudNodeRed.py",
      "type": "nodered",
      "enabled": true
    },
    {
      "name": "MQTT cloud",
      "script": "python CloudMQTT.py",
      "type": "MQTT on test.mosquitto.org",
      "enabled": true
    },
    {
      "name": "GPS",
      "script": "python CloudGpsFile.py",
      "type": "file",
      "enabled": true
    },
    {
      "name": "GroveStreams cloud",
      "script": "python CloudGroveStreams.py",
      "type": "iotcloud",
      "enabled": false
    },
    {
      "name": "Firebase cloud",
      "script": "python CloudFireBase.py",
      "type": "jsoncloud",
      "enabled": false
    },
    {
      "name": "example template",
      "script": "name of your script, preceded by the script launcher",
      "type": "whatever you want FYI",
      "server": "",
      "login": "",
      "password": "",
      "folder": "",
      "write_key": "",
      "enabled": false
    }
  ],
  "encrypted_clouds": [
    {
      "name": "NodeRed flow",
      "script": "python CloudNodeRed.py",
      "type": "nodered",
      "enabled": false
    },
    {
      "name": "MQTT cloud",
      "script": "python CloudMQTT.py",
      "type": "MQTT on test.mosquitto.org",
      "enabled": false
    },
    {
      "name": "Firebase cloud",
      "script": "python CloudFireBaseAES.py",
      "type": "iotcloud",
      "enabled": false
    }
  ],
  "lorawan_encrypted_clouds": [
    {
      "name": "NodeRed flow",
      "script": "python CloudNodeRed.py",
      "type": "nodered",
      "enabled": false
    },
    {
      "name": "MQTT cloud",
      "script": "python CloudMQTT.py",
      "type": "MQTT on test.mosquitto.org",
      "enabled": false
    },
    {
      "name": "Firebase cloud",
      "script": "python CloudFireBaseLWAES.py",
      "type": "iotcloud",
      "enabled": false
    }
  ]
}