Integration with Thingspeak

Good evening!
Im trying to setup an integration from ChirpStack v4 to ThingSpeak and I get a “Last Entry 1 minute ago” after each packet is sent but with no data and when I export the data I find that it has succesfully posted data into the channel but the fields are not there.
*2024-06-11T01:30:48+02:00,28, *
*2024-06-11T01:31:03+02:00,29, *
*2024-06-11T01:31:42+02:00,30, *
2024-06-11T01:31:58+02:00,31,
Last commas should show the fields among other things but are empty
This is how I built the integration:

In the http integration fields:
Payload Encoding: JSON
Event Endpoint URL: https://api.thingspeak.com/update.json
HEADERS:
THINGSPEAKAPIKEY : xxxxxx(hidden but correct)
content-type: application/json

And in the payload decoder functions;

function decodeUplink(input) {
  return {
    data: {
       field1: ((input.bytes[0]<<8 | input.bytes[1]) & 0x3FFF)/1000,
      field2: input.bytes[2]<<8 | input.bytes[3]
    },
    warnings: [],
    errors: []
  };
}

What may I have missed so the payload fields are not posted?
Thanks in advance!

As far as I remember the http integration of Chirpstack sends more data than the decoded one. In order to use the data you will need to process it and send only the relevant information in the required format for the thingspeak API.
You can easily see if sent data is the expected one by sending it to a endpoint and inspecting the JSON, i found this site where you could send your post request and do that.
So (again, as far as I remember), what you need to do is send the post request to a local endpoint, process the data, re-build it in the right format, and re-send it to thingspeak.
In the official documentation there are some tutorials that you could use to easily process the data and resend it to thingspeak, when I did this (several years ago) I used python and the request packages to do it, you are interested (probably) in the uplink event.

Uh… seems like it could be a little more complex than I expected.
I tested the webhook site and I got:

{
  "deduplicationId": "56a22162-2581-4fcb-b934-4d683cXXXX",
  "time": "2024-06-11T20:47:09.233009+00:00",
  "deviceInfo": {
    "tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1dXXXX",
    "tenantName": "ChirpStack",
    "applicationId": "dcf4515b-b78d-4844-9376-e6263c6XXXX",
    "applicationName": "LDDS75",
    "deviceProfileId": "f004e800-0749-43d8-b651-ff7fbfXXXX",
    "deviceProfileName": "LDDS75",
    "deviceName": "LDDS75",
    "devEui": "a84041d1918XXXX",
    "deviceClassEnabled": "CLASS_A",
    "tags": {}
  },
  "devAddr": "017dXXXX",
  "adr": true,
  "dr": 0,
  "fCnt": 0,
  "fPort": 2,
  "confirmed": false,
  "data": "DQoKZQAAAAE=",
  "object": {
    "Field1": 3.338,
    "Field2": 2661
  },
  "rxInfo": [
    {
      "gatewayId": "a8404121e6eXXXX",
      "uplinkId": 52096,
      "gwTime": "2024-06-11T20:47:09.233009+00:00",
      "nsTime": "2024-06-11T20:47:09.225225524+00:00",
      "rssi": -35,
      "snr": 7.5,
      "channel": 2,
      "rfChain": 1,
      "location": {},
      "context": "RvKe9A==",
      "metadata": {
        "region_config_id": "eu868",
        "region_common_name": "EU868"
      },
      "crcStatus": "CRC_OK"
    }
  ],
  "txInfo": {
    "frequency": 868500000,
    "modulation": {
      "lora": {
        "bandwidth": 125000,
        "spreadingFactor": 12,
        "codeRate": "CR_4_5"
      }
    }
  }
}

Field1 and Field2 are actually there, but yeah, among lots of other stuff…

So now I have to send this data to one intermediate program in order to preprocess it before it gets finally sent to ThingSpeak?

Yes, is pretty straight forward, you would need to access the “object” propriety ( or “key”, or whatever is called in the programming language you would use), and send a POST request using the API, as a first approach you could use directly the GET method, but remember that the GET method is not a safe one.

Notice how the http integration forward the events (all the events, not only the uplink), the json that you are seeing (and all other events) can be seen in the event tab in the device.

And that’s a positive thing, to have all the data of the event is important because in more complex applications you could need some or all the information besides the payload.

Ok, but sorry Im a little lost on how all this works
When you say “access the object, send a post, etc” where do I do that?
There’s no such a section in ChirpStack like “program your own code here” :slight_smile:
Where and how do I put this code to preprocess this?
All I can see for programming area is the “custom codec”, like the one I showed above

Thanks again!
PS: Amazed that a google lookup for “Chirpstack to Thingspeak Integration” gives 0 valuable results. Am I the first one trying to connect these 2 systems??

I can assure you that you aren’t the first one to do it, I myself has done that exact thing in the past, my guess is that (no offense) these things are kinda basic concept of programming and how networks and servers works, I can tell that you are new to this, and that’s okey, I was once in yours exact shoes.
Which lead me to the following:

Just in case, when I say object I’m talking in the OOP (Object Orientes programing) way.
Post mean POST request, of the HTTP protocol, you should know how that works before trying to do this, if you don’t all this is going to be very confusing.

No, there’s no such thing as “program your own code here”, please refer to the Chirpstack architecture an the http integration documentation, is stated that the http integration only forward the events.
The HTTP integration only sends the event type format in a POST request, that’s mean that what you are trying to do is out of the scope of the chirpstack stack, that’s why you are not able to find that option in Chirpstack.

So, you need to do your own custom program (aka service) outside of chirpstack that receive the http that chirpstack is sending in order to be used in any other external application, again, this is not hard at all, I’ll give an example of what you should do in python, that’s the easier implementation if you ask me:

  • Using the example provided in the HTTP integration page make a Python script that receive your HTTP POST request, run that code in any port, just be sure not to use any port that is already being used by other application, chirpstack itself, for example, and don’t forget to download the packets used in the python script.
  • Send the HTTP integration to a local port, (the page should be something like http://localhost:[your port there]
  • The python code provided without any modifications will print the raw data received in the events JOIN and UPLINK, you can run this code at it is to make sure that you are receiving the packets.
  • Next you need start working whit your data, you will able to “access the object” in the part of the code that print the data of the Uplink event, there you need to access the desired data and finally send the data to thingspeak whit a POST or GET request, using the necessary python packet (I think is called “requests” or something like that)

In order to do this you will probably need to pass from JSON (javascript) to dictionaries (python) and the other way around, so be sure to understand that kinda thing

Hope this helps you, and if you solve it, please say so

Ups sounds a little complex to me and also it means adding another layer of “something that can end up failing”, in which case I guess we will stick to TTN + ThingSpeak for now, whose integration is straightforward, or finding another visualization platform that can serve us.
BTW can you suggest another IoT cloud system (like ThingSpeak or Thingsboard) which is easy integrable with ChirpStack and lets us offer a simple visualization platform for a client with basic level indicators and alarms? Ideally free or very low cost, for simple projects

Thanks

I mean, yes, kinda, but this process is very straight forward, but if you don’t know much about programming, then yeah, I could see how that could be a problem.

If the TTN platform free (or paid) service suits you, then, go ahead

Thingspeak is, by a long run, the easiest implementation I know, i checked that in Chirpstack V4 there’s a visualization feature that may could do the trick for you, I found a example of how that looks and a little guide here, then again, this is not expected to be used in final deployments of services.

I want to end whit a final advice, from a very personal experience, when you are working whit IoT you will inevitably find yourself in the need of having more deeper knowledge in programing and computer networks, or in the need of hiring a thirdparty that handles that stuff for you.

I advice you and your company to hire someone that knows about these topics, or that someone start learning about these topics.

1 Like

Our service uses ChirpStack and integrates to ThingsBoard by default.
It supports uplink and downlink too.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.