A test program for my SuperTweet driver classes.

Dependencies:   mbed SuperTweet EthernetNetIf

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetNetIf.h"
00003 #include "SuperTweetV1XML.h"
00004 
00005 #define YOUR_ACCOUNT    "YOUR_ACCOUNT"
00006 #define YOUR_PASSWORD   "YOUR_PASSWORD"
00007 
00008 extern "C" void mbed_reset();
00009 
00010 EthernetNetIf net;
00011 SuperTweetV1XML st(YOUR_ACCOUNT, YOUR_PASSWORD);
00012 
00013 /**
00014  * Callback function for postStatusesUpdate.
00015  *
00016  * @param buf A pointer to a buffer.
00017  * @param siz A size of the buffer.
00018  */
00019 void func(char *buf, size_t siz) {
00020 #if 0
00021     /*
00022      * This is for checking a response.
00023      */
00024     for (int i = 0; i < siz; i++) {
00025         printf("%c", buf[i]);
00026     }
00027 #endif
00028 }
00029 
00030 /**
00031  * Entry point.
00032  */
00033 int main() {
00034     char text[BUFSIZ];
00035     int cnt = 0;
00036 
00037     EthernetErr err = net.setup();
00038     if (err) {
00039         error("Network setup failed.\n");
00040     }
00041 
00042     while (1) {
00043         snprintf(text, sizeof(text), "Hi! I'm mbed from ARM. Message number is %d", cnt++);
00044         HTTPResult r = st.postStatusesUpdate(std::string(text), func);
00045         printf("r=%d\n", (int)r);
00046 
00047         /*
00048          * Note:
00049          * I don't know why sometime it get a error.
00050          * I think it a bug in a mbed library.
00051          */
00052         if (r != 0) {
00053             printf("Resetting...\n");
00054             mbed_reset();
00055         }
00056 
00057         wait(5);
00058     }
00059 }