WIFI: How to simply use REST API, Http GET PUT POST ?

Wireless communications in Waspmote, topologies, node types...
Post Reply
namincs
Posts: 10
Joined: Thu Aug 13, 2015 8:31 am

WIFI: How to simply use REST API, Http GET PUT POST ?

Post by namincs » Tue Sep 08, 2015 12:10 pm

[/size]Hi,

I am just trying to do simple things, updating my thingspeak channel.
I am using wifi_26_http_query.pde
sprintf(sentence,"GET$/update?key=KYGNB1BOAJL4B2XG&field4=%d",counter);

I think there is some problem if i try to use IP as server option.
passing #define WEB_SERVER "184.106.153.149"
in
status = WIFI.getURL(IP, WEB_SERVER, sentence);
will fail and give me

Code: Select all

[i]WiFi switched ON
Joined
sentence:GET$/update?key=KYGNB1BOAJL4B2XG&field4=1

HTTP query ERROR
***************************[/i]
But if i use
#define WEB_SERVER "api.thingspeak.com"
Together with
status = WIFI.getURL(DNS, WEB_SERVER, sentence);

It works fine.
The point is. I need to call an IP address as there is no DNS working for the server hosted locally on my application.

Can anyone enlighten me?
Please help as it is blocking my project currently.

ps: i havent mentioned another complication with PUT and POST, i will ask after this is clear
ps2: i heard there is a new wifi lib update? i am still in 017 now.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: WIFI: How to simply use REST API, Http GET PUT POST ?

Post by libelium-dev » Tue Sep 08, 2015 1:27 pm

Hi,

please download the new API v018 ant try again.

Regards.

namincs
Posts: 10
Joined: Thu Aug 13, 2015 8:31 am

Re: WIFI: How to simply use REST API, Http GET PUT POST ?

Post by namincs » Tue Sep 08, 2015 5:55 pm

Hi,

Still failed.
Using IP will never work.

Something wrong when you translate to Wifly command.

Please kindly fix this ASAP.
Or let me know if there is a workaround.
I will help to test.

Thanks

luukh
Posts: 31
Joined: Mon Mar 09, 2015 9:29 pm
Location: Arcadia, Australia
Contact:

Re: WIFI: How to simply use REST API, Http GET PUT POST ?

Post by luukh » Fri Sep 11, 2015 1:19 am

Hi,

I use IP based hostname access in one of my dev environments and it works well. Although I use the a slightly different function call:

Code: Select all

WIFI.getURL(IP, <ip_address>, <base_query_url>, <query_parameters>); 
e.g.
WIFI.getURL(IP, "10.1.1.21", "POST$/sensor/add/.json?", "ts=1234&v=0.7"); 
Referring to the Wifi code library; both getURL functions use almost (if not) identical code structures to set the remote host. It might be nothing, but have you checked your API key is correct (might be expired)? Ie rule out that there are no other issues with the actual HTTP call. You could use another HTTP query tool to confirm the HTTP call is correct. Just a thought.

namincs
Posts: 10
Joined: Thu Aug 13, 2015 8:31 am

Re: WIFI: How to simply use REST API, Http GET PUT POST ?

Post by namincs » Sat Sep 12, 2015 7:17 am

luukh wrote:Hi,

I use IP based hostname access in one of my dev environments and it works well. Although I use the a slightly different function call:

Code: Select all

WIFI.getURL(IP, <ip_address>, <base_query_url>, <query_parameters>); 
e.g.
WIFI.getURL(IP, "10.1.1.21", "POST$/sensor/add/.json?", "ts=1234&v=0.7"); 
Referring to the Wifi code library; both getURL functions use almost (if not) identical code structures to set the remote host. It might be nothing, but have you checked your API key is correct (might be expired)? Ie rule out that there are no other issues with the actual HTTP call. You could use another HTTP query tool to confirm the HTTP call is correct. Just a thought.
Hi luukh,

Thanks for giving some thoughts.
The apikey on the previous example i had to modified, as i cant modify my post.
that key was used for actual thing. :lol:
Anyway i now create another public channel which anyone can try to GET or POST.
Any of these 3 url worked in chrome browser and will update the channel.
http://api.thingspeak.com/update?key=WC ... X&field1=1
http://184.106.153.149/update?key=WCF3C ... X&field1=1
http://144.212.80.11/update?key=WCF3C96 ... X&field1=1

As for libelium wifi libs. Below is my current update.
The IP "184.106.153.149" is probably a dns server IP.
Something which doesnt automatically resolved by wifi lib, unless specifically called DNS.

I am working on some complicated POST now. hopefully no more issues or confusion.

Code: Select all

    //Always worked
    //status = WIFI.getURL(DNS, "api.thingspeak.com", "GET$/update?", "key=WCF3C96CZA4CB53X&field1=1"); 
    //status = WIFI.getURL(IP, "144.212.80.11", "GET$/update?", "key=WCF3C96CZA4CB53X&field1=1"); 
    //status = WIFI.getURL(DNS, "api.thingspeak.com", sentence"); 
    //status = WIFI.getURL(IP, "144.212.80.11", sentence);  
    status = WIFI.getURL(DNS, "184.106.153.149", sentence);  
	
    //Always failed
    //status = WIFI.getURL(IP, "184.106.153.149", "GET$/update?", "key=WCF3C96CZA4CB53X&field1=1"); 
    //status = WIFI.getURL(IP, "184.106.153.149", sentence);  

JTW
Posts: 8
Joined: Wed Nov 28, 2018 2:57 pm
Company: MathWorks, Inc

Re: WIFI: How to simply use REST API, Http GET PUT POST ?

Post by JTW » Tue Mar 19, 2019 5:59 pm

I realize this is an old thread, but there is a ThingSpeak Cloud Connector in the Meshlium now. Details are available in the Meshlium user manual and here.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest