CaySimple - Homemade Android App Demo / Toolkit


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 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(;

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.


@jameszahary Great job i will test !


Hi, the open-source cayenne android java object is coming along nicely, but I have an Authorization question.

I want to build an app to give to other people (normal pre-compiled android app for non-programmers), that accesses my sensors, but does not have my username/password compiled into the code. I assume this is the purpose of the “Create App” with the “APP KEY” and the “APP SECRET”. But I cannot find anything about assigning my sensors to the “App” and then generating an Authorization Token, that I substitute for username/password generated token. Or do I send the APP KEY or APP SECRET in place of the Authorization Token?

I am correct in the assumption that “Create App” does this job?
And could someone send along the 2-3 GETs or PUTs I need to do to get that working?


Hi @jameszahary

Very cool what you have done. Here’s a link to our sample application with detail calls API calls and oAuth flow.


I have to do all this, and reverse engineer some code, to understand how it works? A couple of paragraphs of text would be preferable.


You don’t have to install the application. The readme has enough information to understand API calls and auth flow. In addition, here’s the documentation page for our Platform API

Furthermore, it sounds like what you are trying to accomplish is a kind of sharing capability. We don’t support such feature at the moment.


ok, after some reading …

It seems to me that the Cayenne API is a replacement for the Cayenne website - creating accounts, adding devices, sensors, rules, … all with high quality authentication. It might be used if I am mass producing devices and accounts, and the website is not adequate. But who is doing that?? :grinning:

I was looking for more accessing and displaying the data, with 2-3 devices and a dozen sensors, and perhaps some controls to send messages from a phone to cayenne to the device.

On the matter of sharing sensors: you have the system of sharing “projects” which lets a non-authenticated user look at a webpage of values. I tried copying the device/sensor numbers (which have changed from the logged-in version of the same device/sensor) to access the data with an app, but it doesn’t work. (unless i copied the numbers wrong) That is an option of opening that existing “public” system to give access to the same data within an app.


New version of the simple Cayenne app – notably for the object.

Once you copy the app, the rest is easy.

First, create the object

myCayenne = new Cayenne(cayenneemail, cayennepassword, -7, ErrorStatusBox); // -7 for Mountain, -5 for Eastern, etc

Second, get authenticated.


Third (optional), get a list of all your devices and sensors


This function fills some data structures

myCayenne.SensorArrayList is a list of the names of device and sensor, plus the deviceID and sensorID numbers, and hashmaps




to convert names to numbers and back.

Fourth, get some data the easy way.

You create the object for the data point with the deviceID and sensorID, and give it the name of the box to deposit the result when it arrives is 500ms or so. Your program can continue without suspending the user interface waiting for the data. When you want it refreshed, you call the update function.

myCayDataPoint = CayDataPoint(deviceID, sensorID, (TextView) findViewById(;


Fifth, get some data the fancy way.

The fancy way sets up a callback function, so your program will be alerted and you can do some post-processing to display, manipulate, and react to the data when it arrives in 500ms or so. This example changes some colors and stores the various bits of the data in boxes.

            myCayDataPoint.myResponse.addListener(new Cayenne.CayDataPointRecd() {
            public void CayDataPointRecdHandler_Callback() {

            myCayenne.AddtoBigBox("data handler");

            TextView tv = findViewById(;

            if (myCayDataPoint.v > 20) {
            } else {

            tv = findViewById(;
            tv = findViewById(;
            tv = findViewById(;


And Sixth, draw a graph of your data

You specify the box to draw the graph, 0 or 1 for left or right axis, color of the line, and lower/upper bounds, or just provide the same number if you don’t know the bounds.

myCayDataPoint.updategraph(gv, 0, Color.BLUE, 0.0, 0.0);

Okay, see the example code - easier than typing into this little box.

See the example code as the getCayenneAuth() and getThings() also have callback functions, to launch the next request when the previous one completes.


The display I set out to produce a few weeks ago:


Latest member of the CaySimple family … CayWidget.
Blue box at the top - still needs some high tech artistic flourishes - and a title.