Sending data from Android to Cayenne

Hi, I’m trying to send data to Cayenne from an Android device, that can be picked up by a 8266, and control its behavior. I’ve been trying the REST API command,

POST
https://platform.mydevices.com/v1.1/things/ff6c85e0-2fd2-11e8-9eaa-434cc97e08c2/cmd
with Authorization, Bearer (long number)
and value and channel in the body

It works, but the number is always wrong. I’ve tried lots of combinations of form-data, application/json; charset=utf-8, X-API stuff mentioned on other posts, and it is either rejected, or it replies with a “success” but the data is not there anywhere, and when it does work the data is always a 4-5 digit integer, and never correct. Here are some screens, showing what I am sending, and what arrives. I send 3.14, it arrives at channel 99 on the correct device, but the number is 18266! :confused: Any advice?

rest1

2.71 results in 87029

(previous post had the strange co-incidence of the wrong number and device name!)

Hi @jameszahary,

That’s not the correct path to send data using HTTP.

Here’s the right way:

curl --request POST 
–url https://api.mydevices.com/things/THING_ID/data
–header ‘authorization: Basic base64(MQTT_USERNAME:MQTT_PASSWORD)’ 
–header ‘content-type: application/json’ 
–data ‘[
{
“channel”: 100,
“value”: 27,
“type”: “temp”,
“unit”: “c”
}
] 

Thanks

Reply 1 of 3:

As I understand it, you have a couple of APIs:

  • MQTT API which runs in the micro-controller (pi, 8266, etc) and sends data to the Cayenne Server. This uses the computer generated name/password like 971da7b0-fd21-11e6-ac86-a9a56e70acce and 257f5a90db0155038259970431cxxxxxxxxxx194 which are written in the eprom of the controller.

  • Cayenne API which runs on the user’s computer, webpage, phone, etc and 1. fetchs data from the Cayenne Server, and 2. sends commands to Cayenne Server to create devices, jobs, etc, and 3. sends commands to Cayenne, which are forwarded down to the micro-controller to turn on leds, motors, etc. This uses human control like MrPeanut@gmail.com and peanutpassword, and the oAuth2 authentication derived from those human name/password.

I’m trying to use Cayenne API to tell my wine controller 8266 that it should stop running the First Fermentation Program, and switch to Second Fermentation Porgram, without unplugging it and re-writting a new program into the eprom.

The Cayenne API doc says I can do this with the commands to platform.mydevices.com

Sending a command to a mqtt channel through HTTP api
POST	/v1.1/things/{thingsId}/cmd

I can get his working – that is the authenication and json formats are fine, but the data that arrives is wrong. Many posts on the community having the same problem weeks and years ago. No one seems to have posted a solution. (see post 2)

The idea of using the MQTT API seems in-elegant as I already have the oAuth2 authentication on my Android, but now I’m pretending to be a microcontroller and sending MQTT commands, with those big name/password and Basic authentication with base64 etc, but I gave it a try and cannot get that working either. (see post 3)

So, is there a document or a post, or a human available. If there is a solution, I promise to write it up for the next guy.

Here is the attempt with the Cayenne API technique sending to platform.mydevices.com. This box contains 4 attempts to send 0, 1, 2, 3, and 3.14 and Cayenne gets the numbers 24719, 66656, etc. So, not a success.

$pi@raspberrypi:~ $ curl -X POST \https://platform.mydevices.com/v1.1/things/ff6c85e0-2fd2-11e8-9eaa-434cc97e08c2/cmd
-H ‘authorization: Bearer ey…_s’
-H ‘content-type: application/json; charset=UTF-8’
-H ‘X-API-Version: 1.0’
-d ‘{“channel”:99,“value”:0}’
{“success”:true}

pi@raspberrypi:~ $
pi@raspberrypi:~ $ curl -X POST https://platform.mydevices.com/v1.1/things/ff6c85e0-2fd2-11e8-9eaa-434cc97e08c2/cmd -H ‘authorization: Bearer eyJh…_s’ -H ‘content-type: application/json; charset=UTF-8’ -H ‘X-API-Version: 1.0’ -d ‘{“channel”:99,“value”:1}’
{“success”:true}

pi@raspberrypi:~ $ curl -X POST https://platform.mydevices.com/v1.1/things/ff6c85e0-2fd2-11e8c2/cmd -H ‘authorization: Bearer eyJh…xGI_s’ -H ‘content-type: application/json; charset=UTF-8’ -H ‘X-API-Version: 1.0’ -d ‘{“channel”:99,“value”:2}’
{“success”:true}

pi@raspberrypi:~ $ curl -X POST https://platform.mydevices.com/v1.1/things/ff6c85e0-2fd2-11e8c2/cmd -H ‘authorization: Bearer eyJh…I_s’ -H ‘content-type: application/json; charset=UTF-8’ -H ‘X-API-Version: 1.0’ -d ‘{“channel”:99,“value”:3}’
{“success”:true}

pi@raspberrypi:~ $ curl -X POST https://platform.mydevices.com/v1.1/things/ff6c85e0-2fd2-11e8c2/cmd -H ‘authorization: Bearer eyJ…I_s’ -H ‘content-type: application/json; charset=UTF-8’ -H ‘X-API-Version: 1.0’ -d ‘{“channel”:99,“value”:3.14}’
{“success”:true}

pi@raspberrypi:~ $

On the MQTT API technique, I cannot get past security and syntax checking

I assumed the base64 calc are these names and passwords:

mqttapi1

separated by a single colon, no spaces, with dashes included in username, no round brackets, as follows
mqttapi2

And then sending to api.mydevices … /data … gives a JSON error

pi@raspberrypi:~ $ curl -X POST \

https://api.mydevices.com/things/ff6c85e0-2fd2-11e8-9eaa-434cc97e08c2/data
-H ‘authorization: Basic OTcxZGE3YjAtZmQyMS0xMWU2LWFjODYtYTlhNTZlNzBhY2NlOjI1N2Y1YTkwZGIwMTU1MDM4MjU5OTcwxxxxxxxxxxxxxxxxxxxxOTQ=’
-H ‘content-type: application/json’
-d ‘[{“channel”: 99,“value”: 3.14}]’
{“statusCode”:400,“error”:“Bad Request”,“message”:“Invalid request payload JSON format”}

sending to api.mydevices…/data1 gives a username/password error

pi@raspberrypi:~ $ curl -X POST \

https://api.mydevices.com/things/ff6c85e0-2fd2-11e8-9eaa-434cc97e08c2/data1
-H ‘authorization: Basic OTcxZGE3YjAtZmQyMS0xMWU2LWFjODYtYTlhNTZlNzBhY2NlOjI1N2Y1YTkwZGIwMTU1MDM4MjU5OTcwxxxxxxxxxxxxxxxxxxxxOTQ=’
-H ‘content-type: application/json’
-d ‘[{“channel”: 99,“value”: 3.14}]’
{“statusCode”:401,“error”:“Unauthorized”,“message”:“Bad username or password”,“attributes”:{“error”:“Bad username or password”}}

I also tried data2 and data3, and platform.mydevices.com and mqtt.mydevices.com without success.

So, seeking wisdom! :grinning::confused:

@Neoxelox might be able to help

I had the same problem with random values, but when I had the device disconnected, I mean if I have a device connected to the dashboard and it is sending data to a widget, I can “send” data to that widget via API correctly, I can modify it’s value. I don’t know if I have explained it well…