Data access from Java code on Mac/PC

Hi,

first of all congratulation for the people who are running Thinger.io, very impressive setup.

I am using an Arduino board as an engine monitoring system for an aircraft and send data to the thinger.io Dashboard (Engine RPM, Oil Temperature, …). All is working fine.

I would also like to access the data on a PC/Mac with a program coded in Java.
Arduino --> ESP8266 --> thinger.io --> (cloud) --> Internet WiFi --> PC/Mac

Is it possible to do this ?
If so, is there a Library or a bit of documentation to get me started ?

Thank you for your help.

Best Regards,

Xavier

Hi Xavier,

nice to know you find Thinger.io useful :slight_smile:

Regarding your question, yes, it is possible to access the information in a PC/Mac with Java client, or any other. Unfortunately we don’t have actually a client library for that, although it should be quite easy to build one, at least for accessing device information. I recommend you to find a library for websockets or API rest, depending if you want to access in real-time to the information, or you only need a pooling mechanism.

Once you have such basic client with websockets or API rest calls, I can help you in the calls or the information to send over websockets to start receiving data. But basically you can sniff what the client console is doing by enabling the chrome developer options.

Not sure it would be useful for you, but we recently released the Android source code that uses API rest for interacting with devices. https://github.com/thinger-io/Android-Client

Anyway, I think I can build a sample project in the following days to access the websocket information in real-time. I will keep you updated about that.

P.S.: Your project seems to be awesome! Need some pictures or videos of the dashboard showing real-time data of your aircraft! :blush:

Thank you for your prompt response alvarolb.

I will search for websockets libraries on Java and I am really interested in your sample project using websocket information in real-time.

I will post a screen shot of the Aircraft Engine Telemetry once I have real data and maybe a full HowTo for the full project.

Cheers,

Xavier

Hi again Alvaro,

I am working on the websocket using Tyrus and I am at the point were I get an exception

“Handshake error.”
"Authentication failed."
httpStatusCode : 401

Using another Library I get more info :
WebSocketError : "NOT_SWITCHING_PROTOCOLS"
detail : The status code of the opening handshake response is not ‘101 Switching Protocols’. The status line is: HTTP/1.1 401 Unauthorized

What sort of Authentication should I use to connect to the server ?

Hope you can help.

Cheers,

Xavier

Hi Xavier,

you should try to open a websocket to the device:

wss://api.thinger.io/v2/users/{{your_user}}/devices/{{your_device_id}?authorization={{device_token}}

You will need to create a device token for allowing access to your device, and set it to the URL as authorization.

This way you should have your connection open with the device. In this connection now you can listen for new resources, but you must query them, as the device will only send this information if there is someone listening.

You should send commands like:

{"resource":"{{device_resource_name}}", "interval": {{refresh_interval_in_seconds}}, "enable": true/false}

This way, the command:

{"resource" : "rpm", "interval": 1, enable : true} will query your device to stream the rpm resource every second.

You should query all the resources you want to listen.

Some low level details that can be interesting to know:

  • If you have several websockets open, each one requesting a different refresh interval, the device will send information according to the greatest common divisor between two intervals, and each one will receive the information at the specified rate.

  • If you set a request interval of 0, it means that you are requesting the resource as it is sent by the device and not at an specific rate. It could be useful in your use case, as you could send only information when there are significant change, like ±100 rpm, ± 1 meter in altitud, servo change, etc. If it is properly programmed, it can provide much more responsiveness and reduce bandwidth. Check out a example here http://docs.thinger.io/arduino/#coding-streaming-resources. In this case you can have one websocket open that is listening at a fixed rate, and other listening only for streams. This should work.

Tell me if it works! :slight_smile:

G’Day Alvaro,

Mate your support is amazing, thanks for your help.

ok, I managed to create a connection but instead of using " https://api.thinger.io/v2/users/{{your_user}}/devices/{{your_device_id}?authorization={{device_token}} " --> Same connection error
I used " wss://api.thinger.io/v2/users/{{your_user}}/devices/{{your_device_id}?authorization={{device_token}} " —> connection ok

Is it normal ?

The other good news is that I am receiving data from the device, happy days ! :wink:

Cheers,

Xavier

Great to know you got it working Xavier!! :slight_smile:

Effectively the correct url is this one starting with wss, as it specifies a protocol change to websocket. I will update my post now for future reference.

Waiting pictures of your dashboards and airplane setup!