Can't push data

I’m trying to push data from a PMS-5003 with my own code. When I try to POST the data, the server responds with code 301. Here is a sample data payload:
{
“software_version”: “myfirmware”,
“sensordatavalues”: [
{
“value_type”: “P2”,
“value”: “15.0”
}
]
}

and here is sample output when I test with curl:

$ curl -v -H “Content-Type: application/json” -H “X-Sensor: esp32-xxxxxxxx” -H “X-PIN: 1” --data-binary “@test.jsonhttp://api.sensor.community/v1/push-sensor-data

  • Trying 81.169.180.11:80…
  • Connected to api.sensor.community (81.169.180.11) port 80 (#0)

POST /v1/push-sensor-data HTTP/1.1
Host: api.sensor.community
User-Agent: curl/7.74.0
Accept: /
Content-Type: application/json
X-Sensor: esp32-xxxxxxx
X-PIN: 1
Content-Length: 130

  • upload completely sent off: 130 out of 130 bytes
  • Mark bundle as not supporting multiuse
    < HTTP/1.1 301 Moved Permanently
    < Date: Thu, 06 Jul 2023 22:41:35 GMT
    < Server: Apache/2
    < Location: /v1/push-sensor-data/
    < Access-Control-Allow-Origin: *
    < X-Content-Type-Options: nosniff
    < Transfer-Encoding: chunked
    < Content-Type: text/html; charset=utf-8
    <
  • Connection #0 to host api.sensor.community left intact

When I send the data to http://api-rrd.madavi.de/data.php
instead, it replies with

Sensor: esp32-xxxxxxxx
ok

but the data never show up in grafana.

What am I doing wrong?

Welcome on board!

SC API endpoint: https://api.sensor.community/v1/push-sensor-data/

Headers should be for SDS011:

Content-Type: application/json  
X-Pin: 1  
X-Sensor: esp32-xxxxxxxxxx 

The data should look like this:

{
  "software_version": "something", 
   "sensordatavalues":[
    {"value_type":"P0","value":"XX"},
    {"value_type":"P1","value":"XX"},
    {"value_type":"P2","value":"XX"}
  ]
} 

Madavi API endpoint: https://api-rrd.madavi.de/data.php

Headers should be for SDS011:

Content-Type: application/json  
X-Pin: 1  
X-Sensor: esp32-xxxxxxxxx

The data should look like this:

{
  "software_version": "something", 
   "sensordatavalues":[
    {"value_type":"SDS_P0","value":"XX"},
    {"value_type":"SDS_P1","value":"XX"},
    {"value_type":"SDS_P2","value":"XX"}
  ]
} 

The data is slightly different between the 2 APIs.

Check if the

Thank you so much for the help! I spent most of yesterday trying to figure out what I was doing wrong, with no luck.

My mistake with the SC API was that I was using

https://api.sensor.community/v1/push-sensor-data

instead of

https://api.sensor.community/v1/push-sensor-data/

For madavi, there were 2 problems:

  1. I used P2 instead of SDS_P2 for value_type
  2. Even after I changed it to SDS_P2, my data didn’t show up until I sent all 3 values, SDS_P0, SDS_P1 and SDS_P2. If you leave any of them out, it ignores the sample!

Do we need to upload to both servers, or is it enough to just upload to SC? I am not sure what the madavi API is used for besides grafana.

Also, what update interval is preferred for SC API?

Hi,
Madavi is used for debugging. @ricki-z Do he really have to send to Madavi as well ?
Please use 5 minutes interval. And if some holes appear in the curves reduce a bit.

I was only exporting PM2.5 to the SC API, and was able to see the data through the SC API with

data.sensor.community/airrohr/v1/sensor/81900/

But my sensor was not showing up on the map. Also, I couldn’t see any data via grafana.

Single Sensor view (for map) - Dashboards - Grafana (madavi.de)

After I added PM1 and PM10, it shows on the map and grafana. So the map needs more than just PM2.5 in order to for a sensor to show up. This is a peculiar requirement. I don’t usually bother with anything besides PM2.5, because the PM1 & PM10 estimates tend to be inaccurate.

I am not sending data to the Madavi API, so I guess it isn’t required.

Hello @lincomatic
you need to use your chipID at Madavi (grafana) , not the ID generated by our main database.
And you should change your user agent in the POST request to something unique. Generic requests might be blocked as those are normally made by crawlers which won’t post any data.
Please also change the request URL to /v1/push-sensor-data/ (with the slash at the end). This will generate only one instead of two requests.

@ricki-z,
Yes, I’ve been doing exactly what you asked. The strange thing is just that I had to add PM10, or my sensor wouldn’t show up on the map. Thanks for the reply.