Sensor Data Not Appearing

I have created a sensor asset and have taken the curl example that is displayed and tried it out and it appears the data is not appearing on the server. I go to the webpage full url and i am left with just a [ ] view. The request using -v on curl appears to successfully transmit the data with code 200.

Is there anything i need to check or do for the sensor data to appear on the webpage?

Hmm - well worth asking first: are you sure you “saved” the new sensor asset? A common “gotcha” is that you can “Add new sensor” and view the “Developer” information including the example curl command BEFORE you even save the sensor asset itself. I know I’ve accidentally done that before. :slight_smile:

But it sounds like you also tried viewing data by going to the endpoint in your browser? That would imply the asset was saved.

Since you’re hosted on Farmier I can help debug with you if you’d like. Ping me in the farmOS chat or send me a private message and we can figure it out.

@applecreekacres could you share an example of the data you’re posting to the sensor?

Just reviewing the listener sensor code, it looks like it will always return 200, even if the posted data has issues.

1 Like

Here is the command from the example i used (removing the keys)

curl -H "Content-Type: application/json" -X POST -d '{ "timestamp": 1609254527, "value": 76.5 }' https://applecreekacres.farmos.net/farm/sensor/listener/PUBLIC?private_key=PRIVATE

Then creating my own command of my own data here is what i tried:

curl -H "Content-Type: application/json" -X POST -d "{'timestamp': 1609021800, 'temperature': 68.9, 'wind chill': 68.9, 'dew point': 41.5, 'humidity': 37.0, 'wind speed high': 0.0, 'wind speed average': 0.0, 'wind direction Aaverage': 180.0, 'barometric pressure': 1012.2, 'rainfall': 0.02, 'rainfall rate': 0.02}" https://applecreekacres.farmos.net/farm/sensor/listener/PUBLIC?private_key=PRIVATE
1 Like

Ok so a new development is i did figure out how to properly post using Curl. the problem is the JSON double quotes for the keys need to be escaped on windows. I cannot use the single quotes. It has to all be double quotes enclosed in double quotes.

I had also tried using the python requests library instead of using curl and was not having luck with that.

So the command that worked is this:

curl -H "Content-Type: application/json" -X POST -d "{ \"timestamp
\": 1609254527, \"value\": 76.5 }" https://applecreekacres.farmos.net/farm/sensor/listener/PUBLIC?private_key=PRIVATE
2 Likes

Oh great! Good find, glad you got it working. We should consider improving that response in farmOS 2.x… an error code would make this much easier to debug.

Heres a snippet of a Python script I use to upload sensor values. Something like this should work:

            value = row.get('Value')
            timestamp = row.get('timestamp')

            data = {
                'timestamp': timestamp,
                'temp': value,
            }

            response = requests.post(
                FARMOS_HOSTNAME + SENSOR_PATH + station_id,
                params={'private_key': 'asdfasdf'},
                json=data,
            )
2 Likes

Thanks @paul121. I was using the data parameter, not json. I switched to that and everything is fine with that approach.

2 Likes

@mstenta is the sensor upload rate limited only with the API and if i attached to it as a SQL database it wouldn’t be rate limited?

1 Like

@applecreekacres Farmier hosting limits pushes to 1 data point per minute per sensor. I put this into place just as spam protection. I’ve considered offering an unlimited option for power users, but no one has asked for it yet. :slight_smile:

Are you running into the limit? How often are you hoping to post per sensor?

I am only hitting the limit because of importing historical data. And that’s no big deal. I just put a wait on my post calls and let it go.

It’s not that big of a problem for me that the limit exists.

1 Like

Ha! That’s a good workaround @applecreekacres :slight_smile:

I feel like this idea came up before… and we discussed adding the ability to push multiple data points (multiple timestamps + value(s)) in a single request, but I don’t think we ever dug into that. Could be a good solution for these kind of imports.

I actually need to do the same thing myself at some point - I have a bunch of old Raspberry Pis that have been collecting temperature+humidity data for years. Set them up before farmOS existed and just haven’t gotten around to rewiring them into my farmOS db.

Yeah I have a weather station that can upload to Weather cloud or Weather Underground and I am just looking for a way to have that data exist in FarmOS for long term storage.

1 Like