Wrong Value ThingSpeak | Arduino | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Wrong Value ThingSpeak
Avatar
Tonibco6

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
1
August 3, 2017 - 5:33 am
sp_Permalink sp_Print

I am sending sensor data from the LoRa module (Sodaq ONE) throughtout KPN network. I would like to be able to see this sensor data monitorised within "ThingSpeak", but a '0' value is received constantly. I am not sure whether it happens because the payload is sent in HEX code rather than ASCII...? If so, how can I convert it?

#include "Arduino.h" #include <Sodaq_RN2483.h> #include "DHT.h" #define DHTPIN 2 // Pin connect sensor #define DHTTYPE DHT11 // Define sensor we are using DHT dht(DHTPIN,DHTTYPE); // Initialize the device #define debugSerial SERIAL_PORT_MONITOR #if defined(ARDUINO_AVR_SODAQ_MBILI) #define loraSerial Serial1 #define BEE_VCC 20 #elif defined(ARDUINO_SODAQ_AUTONOMO) || defined(ARDUINO_SODAQ_ONE) || defined(ARDUINO_SODAQ_ONE_BETA) #define loraSerial Serial1 #elif defined(ARDUINO_SODAQ_EXPLORER) #define loraSerial Serial2 #else // please select a sodaq board debugSerial.println("Please select a sodaq board!!"); #endif // ABP const uint8_t devAddr[4] = { }; const uint8_t appSKey[16] = { }; const uint8_t nwkSKey[16] = { }; // OTAA uint8_t DevEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t AppEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t AppKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; void setupLoRaABP(){ if (LoRaBee.initABP(loraSerial, devAddr, appSKey, nwkSKey, false)) { debugSerial.println("Communication to LoRaBEE successful."); } else { debugSerial.println("Communication to LoRaBEE failed!"); } } void setupLoRaOTAA(){ if (LoRaBee.initOTA(loraSerial, DevEUI, AppEUI, AppKey, false)) { debugSerial.println("Communication to LoRaBEE successful."); } else { debugSerial.println("OTAA Setup failed!"); } } void setup() { //Power up the LoRaBEE #if defined(ARDUINO_AVR_SODAQ_MBILI) || defined(ARDUINO_SODAQ_AUTONOMO) pinMode(BEE_VCC, OUTPUT); digitalWrite(BEE_VCC, HIGH); #endif delay(3000); while ((!SerialUSB) && (millis() < 10000)){ // Wait 10 seconds for the Serial Monitor } //Set baud rate debugSerial.begin(57600); loraSerial.begin(LoRaBee.getDefaultBaudRate()); // Debug output from LoRaBee // LoRaBee.setDiag(debugSerial); // optional //connect to the LoRa Network setupLoRa(); } void setupLoRa(){ // ABP setupLoRaABP(); // OTAA // setupLoRaOTAA(); LoRaBee.setSpreadingFactor(9); dht.begin(); //start the device } void sendPacket(String packet){ switch (LoRaBee.send(1, (uint8_t*)packet.c_str(), packet.length())) { case NoError: debugSerial.println("Successful transmission."); break; case NoResponse: debugSerial.println("There was no response from the device."); setupLoRa(); break; case Timeout: debugSerial.println("Connection timed-out. Check your serial connection to the device! Sleeping for 20sec."); delay(20000); break; case PayloadSizeError: debugSerial.println("The size of the payload is greater than allowed. Transmission failed!"); break; case InternalError: debugSerial.println("Oh No! This shouldn't happen. Something is really wrong! Try restarting the device! The network connection will reset."); setupLoRa(); break; case Busy: debugSerial.println("The device is busy. Sleeping for 10 extra seconds."); delay(10000); break; case NetworkFatalError: debugSerial.println("There is a non-recoverable error with the network connection. You should re-connect. The network connection will reset."); setupLoRa(); break; case NotConnected: debugSerial.println("The device is not connected to the network. Please connect to the network before attempting to send data. The network connection will reset."); setupLoRa(); break; case NoAcknowledgment: debugSerial.println("There was no acknowledgment sent back!"); // When you this message you are probaly out of range of the network. break; default: break; } } void loop() { //HumidityDHT1, TempDHT11 String packet = String(dht.readHumidity()) + ", "; packet += String(dht.readTemperature()); debugSerial.println(packet); sendPacket(packet); delay(5000); }

 

https://thingspeak.com/channels/266512

Any suggestion,please?

Many Thanks!

Avatar
cstapels

Gold
Forum Posts: 96
sp_UserOfflineSmall Offline
2
August 3, 2017 - 3:30 pm
sp_Permalink sp_Print

ThingSpeak will accept Hex values as well as ASCII.  Depending on how they are formatted, it may interpret the hex values as strings.  For example, Cheerlights (channel 1417) contains the string from the color name and the hex code in separate fields. I couldn't find information about Lorabee.send() function in a quick google search so I don't know how it works.  I assume it must have the api key correct if you are getting posts to your channel, even if they are zero.

 Perhaps you aren't sending valid field information ('field1=')?  See the documentation on Update a channel feed to make sure your format is correct.  

Also you should try using your browser or POSTMAN to update your channel.  This will help you ensure the format is correct for the request.  You can use the format shown on the API keys page on the right:

GET https://api.thingspeak.com/update?api_key=WRITE_API_KEY&field1=#xxxx  (dont use the GET if you paste it into your browser window)
Avatar
Tonibco6

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
3
August 4, 2017 - 5:47 am
sp_Permalink sp_Print

What do this 5 digits mean "#xxxx" on the browser address?

https://api.thingspeak.com/update?api_key=WRITE_API_KEY&field1=#xxxx

Since I have got a '0' value on my Write keys, so maybe it is the reason it is sending constantly '0' values to my channel.

https://api.thingspeak.com/update?api_key=WRITE_API_KEY&field1=0

If I am sending Humidity and Temperature values to different fields but same channel from a DHT_11 sensor, how can I manage to send it properly?
Field1 = Temperature 
Field 2 = Hmidity

Many thanks!

Avatar
cstapels

Gold
Forum Posts: 96
sp_UserOfflineSmall Offline
4
August 4, 2017 - 2:56 pm
sp_Permalink sp_Print sp_EditHistory

See the documentation at Update a channel feed 

I wrote "field1=#xxx to show you could put Hex numbers in there.

You can continue to append values on the end of the REST call:

 https://api.thingspeak.com/update?api_key=WRITE_API_KEY&field1=11&field2=22   etc.

Avatar
Tonibco6

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
5
August 8, 2017 - 9:43 am
sp_Permalink sp_Print

Still '0' values as result. Well, I got some peaks as I added a random values to each field, but unfortunately then, it keeps coming down to '0'.

This is what my LoRa provider (Sodaq) has messaged me;

You are sending your data correctly to the LoRa gateway (as operated by KPN).

They are forwarding your data on to the specified link you provide. It appears that they use POST and encode the data as JSON. However, this is not in the format that ThingSpeak requires.

You will either have to request that KPN translates the data and forwards in on directly to ThingSpeak, in the correct format. Or setup a some system for doing that yourself. i.e. KPN forwards it in their format to your service, you then translate it and then forward it on to ThingSpeak.

 Does not ThingSpeak allow JASON format, then?

Thanks

Avatar
cstapels

Gold
Forum Posts: 96
sp_UserOfflineSmall Offline
6
August 8, 2017 - 2:26 pm
sp_Permalink sp_Print

Data for updating a field or a feed is not generally formatted as a JSON object when you use the REST API.

You can use JSON format is certain situations, and ThingSpeak will optionally return some output in JSON.  One exception is for a bulk post, which you can provide as a JSON object as shown here.  For your application, I wouldn't necessarily suggest the use of a bulk post.

What do you do to get 'some peaks'?  If you are still using the code above, I would suggest looking at the output of the function (LoRaBee.send(1, (uint8_t*)packet.c_str(), packet.length()) and see how it packages your data.  Then see if that format matches the requirements listed in Update a channel feed .  Since you are getting data to post, but the values aren't going where you want, it must be a format issue.  

Avatar
Tonibco6

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
7
August 11, 2017 - 5:26 am
sp_Permalink sp_Print sp_EditHistory

The peaks made sense because they were coming from the GET request I made several times...however, I was not aware about it at that moment.

So, I have been consulting with my LoRa provider and we believe that KPN is posting a JSON or XML to the destination URL.
ThingSpeak is expecting a GET request.

We believe the only way to solve this is to have a server in the middle what will handle to incoming data from KPN, decode the HEX data and create a GET for ThingSpeak with the correct payload.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

donj51

trilee

Bfletche

stuartWAI

shivmkatiyar

AidanThing

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee