Bulk-Write JSON Data: Error 400, error_duplicate_timestamps with delta_t | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Bulk-Write JSON Data: Error 400, error_duplicate_timestamps with delta_t
No permission to create posts
November 25, 2018
7:33 am
Avatar
hns
New Member
Members
Forum Posts: 3
Member Since:
November 25, 2018
sp_UserOfflineSmall Offline

I try to post via the Bulk-Write JSON API, but I only get an error 400 with the following Response:

{"status":"400","error":{"error_code":"error_duplicate_timestamps","message":"Bad Request","details":"The updates contain identical timestamps."}}

My JSON:

22203892 DEBUG: json to send:
{
"write_api_key": "*******************",
"updates": [
{
"delta_t": 120,
"field1": "19.50",
"field2": "56.34",
"field3": "20.56"
},
{
"delta_t": 60,
"field1": "19.50",
"field2": "56.63",
"field3": "20.61"
},
{
"delta_t": 0,
"field1": "19.44",
"field2": "56.88",
"field3": "20.40"
}
]}

I can not see any "identical timestamps". Any ideas?

November 25, 2018
8:25 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 512
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

If you are making this post more than every 120 seconds, it is possible that the third update overlaps with a previous update. How often are you updating your channel with this bulk post?

November 27, 2018
3:08 pm
Avatar
hns
New Member
Members
Forum Posts: 3
Member Since:
November 25, 2018
sp_UserOfflineSmall Offline

Thanks for the hint. But it seems to be another problem.

At first the client tries to send a single data set via the "update" api (https://api.thingspeak.com/update). If this fails (connection timeout/bad internet) the data will be queued in a buffer and if there are more than 1 entry in the buffer the client sends the data via the bulk api (https://api.thingspeak.com/channels//bulk_update.json)

I think in the past the bulk api worked like expected, but seems to stop working some time ago ...

Today I tried to debug the requests. So I disabled the update POST and used only the bulk update. Every 120s the client POST's two updates, but already the first post fails. Here is a tcp dump:

POST /channels/******/bulk_update.json HTTP/1.1
Host: api.thingspeak.com
User-Agent: ESP8266 (nothans)/1.0
Connection: close
Content-Type: application/json
Content-Length: 196

{"write_api_key": "*******************", "updates": [{"delta_t": 60, "field1": "22.06", "field2": "50.31", "field3": "22.69"},{"delta_t": 0, "field1": "22.06", "field2": "50.36", "field3": "22.65"}]}HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Status: 400 Bad Request
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
Cache-Control: no-cache
Set-Cookie: request_method=POST; path=/
X-Request-Id: c520733c-a5d5-4236-88dc-bbbd0ecab7ed
X-Runtime: 0.013581
X-Powered-By: Phusion Passenger 4.0.57
Date: Tue, 27 Nov 2018 19:44:37 GMT
Server: nginx/1.9.3 + Phusion Passenger 4.0.57

92
{"status":"400","error":{"error_code":"error_duplicate_timestamps","message":"Bad Request","details":"The updates contain identical timestamps."}}
0

November 28, 2018
3:12 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 512
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

I got it after trying your JSON on my channel. delta_t is " Specify time between measurements with delta_t." Its the time from the previous measurement in the list. So when you specify delta_t = 0, that means you are writing it at the same time as the previous measurement, and thus the duplicate timestamps. I will submit a request to clarify the documentation.
https://www.mathworks.com/help/thingspeak/bulkwritejsondata.htm

In one of the examples, it says: "Each entry starts with delta_t and lists the time in seconds from the previous measurement."
But the example is near the end.

delta_t != 0

December 2, 2018
12:15 pm
Avatar
hns
New Member
Members
Forum Posts: 3
Member Since:
November 25, 2018
sp_UserOfflineSmall Offline

Thank you! I thought it is the time difference between the current POST time. I updated my code and now it works like a charm.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
28 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Epiphoneejf, Bbet1814On, Konstantintus, inalv69, bryancv1, priscillaql69

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457