GPS Tweeter program that tweets the device's GPS location every 5 minutes.
Dependencies: EthernetNetIf HTTPClient mbed
Fork of TwitterExample by
main.cpp
- Committer:
- 4180skrw
- Date:
- 2013-10-16
- Revision:
- 4:2d5b7c5b995e
- Child:
- 5:22fb0d9a5de2
File content as of revision 4:2d5b7c5b995e:
#include "mbed.h" #include "EthernetNetIf.h" #include "HTTPClient.h" #include "GPS.h" EthernetNetIf eth; GPS gps(p13, p14); int main() { // Setup the time structure char buff[141]; printf("Initialization in Process\n"); EthernetErr ethErr = eth.setup(180000); if(ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } printf("\r\nSetup OK\r\n"); //wait(45); // Setup objects for sending the tweet. HTTPClient twitter; HTTPMap msg; while(1) { printf("\Attempting to Read in From the GPS Device\n\r"); gps.sample(); if(gps.sample()) { printf("I'm at %f, %f\n\r", gps.longitude, gps.latitude); sprintf(buff,"I'm at %f, %f", gps.longitude, gps.latitude); //sprintf(buff,"Hey Guys, today I decided to take up a new hobby to cook. I will be making some amazing thing."); msg["status"] = buff; twitter.basicAuth("4180SKRW", "welcome1"); //We use basic authentication, replace with you account's parameters //No need to retieve data sent back by the server HTTPResult r = twitter.post("http://api.supertweet.net/1.1/statuses/update.json", msg, NULL); if( r == HTTP_OK ) { printf("Tweet sent with success!\n"); } else { printf("Problem during tweeting, return code %d\n", r); } } else { printf("Oh Dear! No lock :(\n\r"); sprintf(buff,"hello my name is richard"); msg["status"] = buff; twitter.basicAuth("4180SKRW", "welcome1"); //We use basic authentication, replace with you account's parameters //No need to retieve data sent back by the server HTTPResult r = twitter.post("http://api.supertweet.net/1.1/statuses/update.json", msg, NULL); if( r == HTTP_OK ) { printf("Tweet sent with success!\n"); } else { printf("Problem during tweeting, return code %d\n", r); } } wait(60*5); } return 0; }