I have an arduino connected to a temp/humidity.pressure sensor and want to send the data to a PAC via an http POST request. I have the PAC configured with http on port 80 and a GET request running successfully. I’m using Postman as a guide to generate code for arduino.
Postman shows the following HTTP code for a Get request.
GET /api/v1/device/strategy/vars/floats/Humidity HTTP/1.1
Host: 192.168.0.40
Authorization: Basic UG9zdDpydzAxMTU=
Cache-Control: no-cache
Postman-Token: d6ff81ea-8066-5923-2cc9-5e365e52daa6
I implemented in arduino (after establishing Ethernet connection) as :
httpClient.println(“GET /api/v1/device/strategy/vars/floats/Humidity HTTP/1.1”);
httpClient.println(“Host: 192.168.0.40”);
httpClient.println(“Authorization: Basic UG9zdDpydzAxMTU=”);
httpClient.println();
and it works successfully to return the current value. Actual return is:
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked0018
{“value”:3.12000008e+01}
0
Now trying to get POST request to work. . .
Postman HTTP code for successful POST is:
POST /api/v1/device/strategy/vars/floats/Humidity HTTP/1.1
Host: 192.168.0.40
Authorization: Basic UG9zdDpydzAxMTU=
Cache-Control: no-cache
Postman-Token: 0df8d1e8-168e-3073-1bcd-d1bf3c152046{
“value” : 33.3
}
I attempted implementing in arduino as:
httpClient.println(“POST /api/v1/device/strategy/vars/floats/Humidity HTTP/1.1”);
httpClient.println(“Host: 192.168.0.40”);
httpClient.println(“Authorization: Basic UG9zdDpydzAxMTU=”);
httpClient.println();
httpClient.println(“{”);
httpClient.println(“"value" : 33.3”);
httpClient.println(“}”);
httpClient.println();
The following HTTP was returned:
HTTP/1.1 400 Device Request Error
Content-Type: application/json; charset=UTF-8
Content-Length: 87
{“errorCode”:-8,“message”:“See Opto 22 documentation for error code descriptions.”}
HTTP/1.1 501 Not Implemented
Content-Length: 0
Other HTTP code returned from failed POST request
HTTP/1.1 401 Not Authorized
Content-Type: text/html
WWW-Authenticate: Basic realm=“Authorization Required”
I’ve added an additional set of read/write keys and tried them, but no success.
On rare occasion, I’ve received a 200, success from the Post request, but the value of Humidity was notstrong text changed on the PAC.
Can someone please help me identify the problem?