Skip to first unread message

Timothy Woo

unread,
Oct 4, 2016, 11:07:43 PM10/4/16
to mitappinv...@googlegroups.com
Hi there,

I followed this wonderful tutorial and successfully programmed my NodeMCU (ESP8266 WiFi board) to post data onto DeviceHub.net, but I am having trouble scraping the data from DeviceHub.net onto my Android phone via MIT App Inventor 2.
Basically when you set up an account on DeviceHub.net you add a project, device, and sensor and they give you an API key as well as device UUID. I used this info to successfully post data onto the database, but I can't retrieve it with my phone, because I am not sure how to implement the API key. I want to be able to open the app and grab the last data point that was entered on the phone. The link I used in the Arduino IDE code to post data to was like this:


but it had an API key header.

Here is what I have so far for MIT App Inventor 2 (obviously with the info filled in):



Basically, whenever someone hits the "Refresh" button I want to grab the very last data point that was stored onto the database by the NodeMCU module. Again, I really don't know what to do with the API key. When I paste the URL into my browser I get {"detail":"Authentication credentials were not provided."}

Any help would be much appreciated.

Thanks!

Abraham Getzler

unread,
Oct 5, 2016, 9:15:23 AM10/5/16
to MIT App Inventor Forum
The capitalized words in the URL are probably meant to be replaced by actual values for your project and device,
as registered at their web site.

Notice how they appear twice, once capitalized and another time lower case.

If that doesn't help, post your sketch code here too.

See the Web Services section of this FAQ:

If you get it working, come back here with your solution and I'll add it to the FAQ.
That's a nice tutorial.

ABG

Timothy Woo

unread,
Oct 5, 2016, 10:14:07 AM10/5/16
to MIT App Inventor Forum
Yes, I just left those unfilled so I wouldn't give away my API key and the other info (heard it's bad practice). I filled those all caps places in and successfully was able to push data to the database.
I think I am very close to getting the app side figured out, I am trying to parse through the web response.

Thanks,
Tim

Timothy Woo

unread,
Oct 5, 2016, 12:45:15 PM10/5/16
to MIT App Inventor Forum
I finally got it working!

What I did was I had to add a "Request Header" block to include my API key. Then I used the HtmlTextDecode block and from there I just split the data to get rid of delimiters (quotation marks, commas, etc) so that everything was spaced out by exactly 1 space. From there I found a starting and ending index in which the actual number I want has to lie within. Here is the updated block diagram:


Since I only needed the last value, I added "?limit=1" at the end of the web URL's that have the whiteouts. This makes it so that we only receive 1 value, and it made the app a lot faster.
As I mentioned before, for the NodeMCU part for POST and GET to the API, please see this great tutorial that I followed

Hope someone will find this useful!

~Tim
Reply all
Reply to author
Forward
0 new messages