After reading the forum post "Stumped on HTTP client..." http://mbed.org/forum/mbed/topic/3546/ the answer might be "wait for the official networking support from mbed" but I thought I would post in case someone can offer the vital clue to fix my issues ;)
I'm really excited about the internet of things and want to connect my mbed to the web for pachube (now cosm) and NTP. I've bought a TMP102 and got it working with printf within minutes with the excellent apis available here, and I've also been experimenting with a LED matrix display. Next task is to make it internet connected.
For ethernet, I've tried some of the examples out there already on mbed but all seem to do the following:
- setup ethernet
- get DHCP address OK (and appear on my router IP list)
- try and post or get something from the web but just hang, no timeout, no error, nothing.
The successful DHCP should indicate my ethernet breakout is wired ok.
Is there a way to enable extra debug messages to understand why this is hanging?
The device is a LPC2368.
The code I've tried include:
- NTP Client: http://mbed.org/cookbook/NTP-Client
printf output:
Quote:
==============================
Start
Setting up ethernet...
[..\fwk\if\eth\EthernetNetIf.cpp:setup@86] HW Addr is : e2:10:31:a9:d7:2f.
[..\fwk\if\eth\EthernetNetIf.cpp:setup@99] DHCP Started, waiting for IP...
[..\fwk\if\eth\EthernetNetIf.cpp:setup@142] Connected, IP : 192.168.0.150
Setup ethernet OK
Reset time to NULL
Current time is (UTC): Thu Jan 1 00:12:26 1970
Access NTP...
From this code:
#include "mbed.h"
#include "EthernetNetIf.h"
#include "NTPClient.h"
EthernetNetIf eth;
NTPClient ntp;
int main() {
printf("==============================\n");
printf("Start\n");
printf("Setting up ethernet...\n");
EthernetErr ethErr = eth.setup();
if(ethErr)
{
printf("Error %d in setup.\n", ethErr);
return -1;
}
printf("Setup ethernet OK\n");
printf("Reset time to NULL\n");
time_t ctTime;
ctTime = time(NULL);
printf("Current time is (UTC): %s\n", ctime(&ctTime));
printf("Access NTP...\n");
Host server(IpAddr(), 123, "0.uk.pool.ntp.org");
NTPResult NTPerror;
//Read time from NTP server
NTPerror = ntp.setTime(server);
printf("Result...\n");
if (NTPerror == NTP_OK) printf("NTP - Time set");
else { //an NTPerror, but which one
switch (NTPerror) {
case NTP_TIMEOUT:
printf("NTP - timeout\n");
break;
case NTP_DNS:
printf("NTP - DNS error\n");
break;
case NTP_PRTCL:
printf("NTP - Protocol error\n");
break;
default:
printf("Unknown error\n");
}
printf("END.\n");
return -1;
}
ctTime = time(NULL);
printf("\nTime is now (UTC): %s\n", ctime(&ctTime));
while(1)
{
printf("\nTime is now (UTC): %s\n", ctime(&ctTime));
wait(5);
}
}
The other one I tried was this pachube example (with my own api key and feedid, and pachube replaced with 'cosm'. Output:
Quote:
Setting up...
Setup OK
Json: { "title":"TITLE HERE", "version":"1.0.0", "datastreams":[ { "id":"STREAM ID", "current_value":"9"}, { "id":"STREAM ID", "current_value":"67"} ]}
client.post HTTPResult...
Here's the relevant section of the code from this example: http://mbed.org/users/takashikojo/programs/Pachube-v2_MyFeed/m0l93r/docs/main_8cpp_source.html
..cut..
// for authentication, API key is set in client header
HTTPClient client;
client.setRequestHeader("X-PachubeApiKey", apiKey);
// text object holds data to be posted
HTTPText jsonContent("text/json");
while (1) {
sprintf(content, contentTemplate, rand()%40, rand()%100) ;
printf("Json: %s\n", content) ;
jsonContent.set(content) ;
// uri for post includes feed ID
string uri = "http://api.cosm.com/v2/feeds/" + environmentID + ".json?_method=put";
printf("client.post HTTPResult...\n");
// result should be 0 and response should be 200 for successful post
HTTPResult result = client.post(uri.c_str(), jsonContent, NULL);
if (result==HTTP_OK) {
printf(" OK: \"%s\"\n", txt.gets());
} else {
printf(" Error: %d\n", result);
}
..cut...
Am I missing something fundamental here? I've tried searching through mbed posts and comments etc but not solved my issue :) I've also tried playing with my router to put the mbed ethernet address on DMZ in case of firewall issues.
If anyone can give any pointers to help me solve this I'll be very happy!
Thanks!
Neil.
After reading the forum post "Stumped on HTTP client..." http://mbed.org/forum/mbed/topic/3546/ the answer might be "wait for the official networking support from mbed" but I thought I would post in case someone can offer the vital clue to fix my issues ;)
I'm really excited about the internet of things and want to connect my mbed to the web for pachube (now cosm) and NTP. I've bought a TMP102 and got it working with printf within minutes with the excellent apis available here, and I've also been experimenting with a LED matrix display. Next task is to make it internet connected.
For ethernet, I've tried some of the examples out there already on mbed but all seem to do the following: - setup ethernet - get DHCP address OK (and appear on my router IP list) - try and post or get something from the web but just hang, no timeout, no error, nothing.
The successful DHCP should indicate my ethernet breakout is wired ok.
Is there a way to enable extra debug messages to understand why this is hanging?
The device is a LPC2368.
The code I've tried include: - NTP Client: http://mbed.org/cookbook/NTP-Client
printf output:
Quote:
From this code:
The other one I tried was this pachube example (with my own api key and feedid, and pachube replaced with 'cosm'. Output:
Quote:
Here's the relevant section of the code from this example: http://mbed.org/users/takashikojo/programs/Pachube-v2_MyFeed/m0l93r/docs/main_8cpp_source.html
Am I missing something fundamental here? I've tried searching through mbed posts and comments etc but not solved my issue :) I've also tried playing with my router to put the mbed ethernet address on DMZ in case of firewall issues.
If anyone can give any pointers to help me solve this I'll be very happy!
Thanks!
Neil.