Here is a homemade Android App demo and toolkit. You can edit in your own username/password, and your devices/sensors, and download it to your android device, or cut and paste and make up your own interface. The top 1/3 of the screen is a scrolling list of status, errors, and exceptions which you can drag up to see old messages. The bottom 1/3 shows 4 boxes containing 4 datapoints with value, unit time and data, and how old the data is. And the middle 1/3 shows 24 hour graph of the bottom two datapoints. 8 hours of the 24 hours is visible and you drag to the left or right to see the entire sample.
See later for more instructions about how it works, and what the buttons do, but first here are the instructions to install.
Step 1
Download and install Android Studio - its free.
Step 2
Go to GitHub - jameszah/CaySimple: Simple Android App to display Cayenne mydevices.com data and history and download the zip file containing the project.
Step 3
Unzip the file and open it with Android Studio using the âOpen an existing project âŚâ and selecting the folder of the unzipped CaySimple project.
Step 4
Open the directory
Project â app â java â com.james.caysimple â SimpleActivity and edit in your cayenne username and password, and 2 devices and 4 sensors. I use 3 sensors on one device, and the 4th sensor on another device. Change that as you choose. The sensors shown will not work for you, as they are mine.
You can get the device / sensor numbers 8x-4x-4x-4x-12x by opening your web dashboard, then clicking on the Settings in the upper-right of the sensor, and then the url showing on your browser should look like this:
The first 8x-4x-4x-4x-12x is the device, and the second is the sensor.
Step 5
Open the directory
Project â app â res â layout â activity_simple.xml and fiddle around as you choose. On this snapshot it shows the device is a Galaxy s7, which is not one of the pre-installed options. The boxes will all get shuffled around for larger or smaller screens, so you may have to make the boxes smaller to fit everything in for your device. There is a bit of a learning curve figuring out how to fiddle with all the boxes and settings.
Step 6
Connect your android device to the computer with a usb.
Your android device will need to be set up to receive a downloadable program from your pc. Instructions here:
Step 7
Click the Run âappâ button and it will compile, download, and run the app on your device.
Step 8
Obviously you will have to go through the java code and change the scales on the graph, and sizes of boxes for your data.
Usage Instructions
When the CaySimple app starts, it first checks if it can access the internet by checking the time. The time is printed in the box at the top of the screen. You can click the GET TIME button, to re-query and print the time in the box.
If it can access the internet, then CaySimple will turn on the GET CAY AUTH button, and then send your username/password to Cayenne to get your Authorization Token. It will print it in the box at the top. You can re-query it by clicking the GET CAY AUTH button. The box at the top of the screen scrolls down, but you can drag it back up to see the information that runs off the bottom.
Finally, if you successfully get your Auth Token, then it will turn on the CAY DATA button. Click the CAY DATA button and it will send 6 queries to Cayenne, and about 500ms later the data should appear in the 4 blue boxes, and the last 24 hours of data will be queried for the two temperature sensors that are the bottom two sensors in the blue boxes. See the java code for which sensor goes in which box. The code also shows how to change colors on the 3rd box based on the value of the sensor.
The graph starts with the most recent data on the right, and then 8 hour old data on the left, and you can drag the graph to see the last 24 hours of data.
The times in the Cayenne database are UTC time, and they are all changed in the code to Mountain Standard Time with the -7 hours calculations. You can edit that for your own timezone. The standard java timezone functions to too difficult to understand, so I just subtracted the seconds.
The box at the top will show each data point arriving, and the time/date of the data, and how old the data is in seconds, and the milliseconds it took between the query and the response from cayenne.
Also you can click the bottom two blue boxes to update those 2 temperatures, without requesting all 4 points and redrawing the graph. Obviously you will have different sensors in those boxes.
The important bits of the java code:
getTime() - gets the time and prints it in the top box (to confirm internet is working
getCayenneAuth() - gets your Authorization Token based on your username/password
The heart of the program is the class CayDataPoint. You create a datapoint with
currentTemp = new CayDataPoint(deviceID, sensorIDtemp, (TextView) findViewById(R.id.newDataTemp));
where deviceID and sensorID are the 8x-4x-4x-4x-12x numbers of your sensor and newDataTemp is the name of a box on your screen where the data and time will be deposited when the information arrives from Cayenne.
The ânew CayDataPointâ call just creates the object. When you want the data, you call currentTemp.update(); and the object will request it from Cayenne, and put it in the box newDataTemp, and also store it in the object, so you can access the value and time with currentTemp.v and currentTemp.ts. Be aware you cannot access these values immediately after the update() call, as it will take 500ms or up to 10,000ms for Cayenne to respond and store the data in currentTemp.v If Cayenne does not respond within 10 seconds, you will get a timeout message in the box at the top to the screen. The box will also contain error messages and exception messages if things are going wrong. To draw a datapoint on the graph, you call currentTemp.updategraph(), and it will request 24 hours of data and put it on the graph for the currentTemp sensor.
This is just a starting point to make it easier to access the data. You could add a dozen DataPoints with nice drawings of your machinery, or multiple graphs, and fiddle with how you want the time displayed, if at all.
Also, use at your own risk.
The app aborted plenty of times during the development, and caused no problems with my Samsung Galaxy S7, but you never know. You can just re-start the app, or edit the code and xml screen layout, and then run the app again, and it will download and store itself on your device. And you can delete it in the usual way of deleting apps.
Let me know if anyone gets it working, or have questions.
The tutorials of Neoxelox were the starting point of this app, and contain detailed explanations on the cayenne REST API calls.