Localisation not updated through bulk_write API

Thomas on 14 Mar 2023 (Edited on 14 Mar 2023)
Latest activity Reply by Thomas on 14 Mar 2023

Hello people,
I made a program to read a dataset from JSON and make an API request to Thingspeak (bulk_write).
After the transmission I display the response of the request, which is 202 (compliant data).
My data updates fine on my Thingspeak channel but the longitude and latitude fields do not change.
Do you have any explanation for this problem?
Here is the code:
import json
import requests
import time
apiKey = "xxxxxxxxxxxxxxxx"
channel_ID = "xxxxxxx"
url = "https://api.thingspeak.com/channels/" + channel_ID + "/bulk_update.json" # ThingSpeak server settings
message_buffer = []
message = {}
while True:
f = open("data.json", "r")
jsonContent = f.read()
objJson = json.loads(jsonContent)
message['delta_t'] = 15
message['field1'] = (objJson['GPS']['speed'])
message['field2'] = (objJson['GROVE'][3]['degNord'])
message['field3'] = (objJson['GIROUETTE']['degVent'])
message['latitude'] = str((objJson['GPS']['latitude']))
message['longitude'] = str((objJson['GPS']['longitude']))
message['elevation'] = 100
latitude = (objJson['GPS']['latitude'])
longitude = (objJson['GPS']['longitude'])
#print(latitude)
#print(longitude)
message_buffer.append(message)
bulk_data = json.dumps({'write_api_key':apiKey,'updates':message_buffer})
print(bulk_data)
message_buffer = []
request_headers = {"User-Agent":"mw.doc.bulk-update","Content-Type":"application/json","Content-Length":str(len(bulk_data))}
print(request_headers)
response = requests.post(url,headers=request_headers,data=bulk_data)
print (response) # Response 200 : Validated data / Response 429 : Too many request, please wait
print("_________________________________________")
print()
time.sleep(15)
My JSON file :
{
"GPS": {
"latitude": 48.75607,
"longitude": 2.30202,
"speed": 10.04384
},
"GROVE": [
{
"Compas": {
"x": 2.583,
"y": -4.439,
"z": 0.435
}
},
{
"Gyroscope": {
"x": 2.56433,
"y": -4.45352,
"z": 0.47237
}
},
{
"Acceleration": {
"x": 0.28,
"y": 0.01,
"z": 0.93
}
},
{
"degNord": 20.743
}
],
"GIROUETTE": {
"degVent": 30.46389
}
}
Thomas
Thomas on 14 Mar 2023
I don't use the read API endpoint, but I look the channel location on the website. I just remark that the values "longitude", "latitude" and "elevation" are not updated. But all the fields are updated.
Christopher Stapels
Christopher Stapels on 14 Mar 2023
Bulk update does not change the channel location. The channel feed is updated from any updates.
Channle location is a reletively static location.
I like to think of the channel location as home base for a plane. The channel location is the home base, airport, hangar station, etc. The feed contains the present location of the device, airplane, helicopter drone.
Or say you put a GPS on your bike. The garage would be the channel location and the feed parameters would tell you where your bike is at any given moment.
Thomas
Thomas on 14 Mar 2023
Okay, I get the idea.
I'll do the necessary.
Thanks for the quick answers !
Christopher Stapels
Christopher Stapels on 14 Mar 2023
The latitude and longitude for the channel (i.e. channel home location) are set using the write settings endpoint, using the user API key. For bulk update, you will change the feed parameters (each point). Use the read API endpoint with location=true to see position information.
Christopher Stapels
Christopher Stapels on 14 Mar 2023
Here you can see a discussion about how to make a map of location points from your channel