Android client ThingSpeak extension for MIT Application Inventor 2

Skip to first unread message

Andre Castro

May 18, 2019, 8:54:05 AM5/18/19
to MIT App Inventor Forum

The following attached file contains a ThingSpeak client extension Name:  IconTS.png
Views: 16
Size:  785 Bytes that allows one to easily make use of the Read and Write features of the ThingSpeak cloud service provided by MathWorks in such a manner that programmer is able to transparently make use of the service without having to deal with much details of the implementation in the code side. With the App - also attached - you can easily check the extension working on a friendly interface:

Click image for larger version. 

Name:	AppRunning.png 
Views:	3 
Size:	66.5 KB 
ID:	153144

Essentially ThingSpeak is a Web server on which data is read and written via GET commands of the Http protocol. All replies come on the JSon format in raw text with no formatting, which means that no LF or CR characters are added, as can be seen on the left side of the following picture:

Click image for larger version. 

Name:	JSonFormatter.png 
Views:	1 
Size:	70.0 KB 
ID:	153161 
( picture taken form Jsonformatter )

All you have to do is subscribe to the ThingSpeak website, create a channel, and take note of the following data automatically generated:

Click image for larger version. 

Name:	ThingSpeak.png 
Views:	2 
Size:	55.6 KB 
ID:	153171

It is important to note that all data sent and received are in the ASCII format at the URL body, which means that if one wish provide extra security, it should be considered any kind of cyphering or even cryptography in order to atleast detect whether data was maliciously corrupted or not. Another poit to remark is that parsing was performed without using any JSon library, which means that if on the one hand the structural integrity of the JSON format is not checked out, on the other hand it means that tasks are performed lightweight, not wasting core processing if application require update realtime.

Here's an overview of the "source code" or rather, "source blocs" of the above demo application.
That's all you need, nothing else:

Click image for larger version. 

Name:	AppProject.png 
Views:	4 
Size:	78.6 KB 
ID:	153145

Below, a snapshot of the components:

Click image for larger version. 

Name:	Components.png 
Views:	1 
Size:	96.9 KB 
ID:	153149

Here, a snippet showing how much of the boring coding task can be avoided by customer, once it is embedded on the extension itself:

Click image for larger version. 

Name:	Snippet.png 
Views:	2 
Size:	43.9 KB 
ID:	153170

This project is also available on Github repository, at which releases will be updated.

Parameters to Fill:
  • Channel: A number containing 6 or 7 decimal digits which is the ID of the channel
  • ReadKey: The alphanumerical key provided by ThingSpeak to read the channel you have just created
  • WriteKey: The alphanumerical key provided by ThingSpeak to write at the channel you have just created
  • Field: One of the 8 available at each channel
  • Value (w): The value (atually, a string) to be stored at the cloud service
  • Security: The mode you selected to grant access to the channel (public/ private)

Returned parameters:
  • TimeStamp: Date-Time of the last value updated to cloud server
  • Value (r): Value got from cloud server (Read:Field content / Write:Opperation succeeded)
  • Status: Just to trace some inner status of the component during execution
Feel free to make experiments and give feedback.

Andre Castro

May 18, 2019, 8:57:43 AM5/18/19
Oddly, every time I tried to upload the attached file, an error occurred, so it is here on this reply.

Chris Ward

May 18, 2019, 9:12:53 AM5/18/19
to MIT App Inventor Forum
Hello Andre

Thank you for your comprehensive guide to ThingSpeak. I know some App Inventor Users, especially students, are using it (many use it with their microcontroller data). If you don't mind, it would be good to reference your post in Abraham Getzler's App Inventor FAQ. If that is OK, please give your permission here.

Concerning the battle to upload a file, a Project that includes an extension is banned by Google (classed as dangerous). MIT bans APK files as these could be malicious, or silently replaced with a malicious file.

Andre Castro

May 18, 2019, 9:24:19 AM5/18/19
to MIT App Inventor Forum
Hi Chris,

I'm glad to know it will be usefull for others, particularly students, and of course, I give my permission to do that.
It they find some problem/improvement, please ask them to report it at the Issues tab on the Github repository, ok?



May 19, 2019, 3:03:41 PM5/19/19
to MIT App Inventor Forum
Reply all
Reply to author
0 new messages