Community
OpenEnergyMonitor

OpenEnergyMonitor Community

New Emoncms feed data bulk upload API

I’ve added a new and arguably long needed API for bulk upload of feed data to Emoncms (Currently available in the emoncms master branch).

While it is already possible to upload data via the input/bulk API this can be a bit cumbersome to work with if you just want to upload data to a specific feed, without worrying about input processing setup etc.

The new API is integrated in the /feed/insert API end point which now supports a new optional parameter to upload multiple data points. It’s possible to upload data either in the URL or in the post body.

Timestamps are all unix timestamps in seconds

Option 1: GET request (data in the URL)

GET http://emonpi.local/feed/insert.json?id=FEEDID&data=[[1598627750,100],[1598627760,150],[1598627770,200],[1598627780,250]]

Option 2: POST request (data in the post body)

POST http://emonpi.local/feed/insert.json?id=FEEDID
data=[[1598627750,100],[1598627760,150],[1598627770,200],[1598627780,250]]

Python example

import requests, time, json, math
server = "http://emonpi.local"
feedid = 1
apikey = 'APIKEY'

# Build some example data
data = []
for i in range(360):
    timestamp = int(time.time()+(i*10))-3600
    value = "%.2f" % (100+50*math.sin(6.28*i/360))
    data.append([timestamp,float(value)])

print("Example data:")
print(data)

result = requests.post(
    server+"/feed/insert.json",params={'id':feedid,'apikey':apikey},
    data={'data':json.dumps(data)}
)

print(result.text)

The result in emoncms:

@TrystanLea
Great - how does one access it in master?
Thx

cd /var/www/emoncms
git fetch
git checkout master
git pull

Note an update may switch you back to Stable.

Manually switching back to stable

git checkout stable
git pull

Did you update the API docs?