Use Seeed Wifi shield and WiflyInterface to send current time to the Xively Service

Dependencies:   WiflyInterface libxively mbed

Fork of Wifly_HelloWorld by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
lz307
Date:
Sat Nov 09 01:02:05 2013 +0000
Parent:
5:867d16e948eb
Commit message:
Use the Seeed wifi shield and WiflyInterface to send the current time to the Xively Service.

Changed in this revision

WiflyInterface.lib Show annotated file Show diff for this revision Revisions of this file
libxively.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
xi_user_config.h Show annotated file Show diff for this revision Revisions of this file
--- a/WiflyInterface.lib	Fri Aug 24 13:52:40 2012 +0000
+++ b/WiflyInterface.lib	Sat Nov 09 01:02:05 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/WiflyInterface/#fb4494783863
+http://mbed.org/users/lz307/code/WiflyInterface/#3152fcc74390
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libxively.lib	Sat Nov 09 01:02:05 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/xively/code/libxively/#4ce6299f7535
--- a/main.cpp	Fri Aug 24 13:52:40 2012 +0000
+++ b/main.cpp	Sat Nov 09 01:02:05 2013 +0000
@@ -1,5 +1,10 @@
 #include "mbed.h"
 #include "WiflyInterface.h"
+#include "xively.h"
+#include "xi_err.h"
+
+#define XI_FEED_ID 273104668 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "Your API Key" // set Xively API key (double-quoted string)
 
 Serial pc(USBTX, USBRX);
 
@@ -11,11 +16,56 @@
 *     - "password" is the password
 *     - WPA is the security
 */
-WiflyInterface wifly(p9, p10, p25, p26, "mbed", "password", WPA);
+WiflyInterface eth(p9, p10, p25, p26, "ssid", "passwd", WPA);
+
+int main()
+{
+    int s = eth.init(); //Use DHCP
+
+    if( s != NULL ) {
+        printf( "Could not initialise. Will halt!\n" );
+        exit( 0 );
+    }
+
+    s = eth.connect();
+
+    if( s == false ) {
+        printf( "Could not connect. Will halt!\n" );
+        exit( 0 );
+    } else {
+        printf( "IP: %s\n", eth.getIPAddress() );
+    }
+
+    xi_feed_t feed;
+    memset( &feed, NULL, sizeof( xi_feed_t ) );
+
+    feed.feed_id = XI_FEED_ID;
+    feed.datastream_count = 1;
 
-int main() {
-    wifly.init(); // use DHCP
-    while (!wifly.connect()); // join the network
-    printf("IP Address is %s\n\r", wifly.getIPAddress());
-    wifly.disconnect();
-}
\ No newline at end of file
+    feed.datastreams[0].datapoint_count = 1;
+    xi_datastream_t* orientation_datastream = &feed.datastreams[0];
+    strcpy( orientation_datastream->datastream_id, "orientation" );
+    xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
+
+    // create the cosm library context
+    xi_context_t* xi_context
+    = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
+
+    // check if everything works
+    if( xi_context == NULL ) {
+        return -1;
+    }
+
+    while(1) {
+        time_t seconds = time(NULL);
+        char buffer[32];
+        // get the current time
+        strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
+        xi_set_value_str( current_orientation, buffer );
+        printf( "update...\n" );
+        // send to xively server
+        xi_feed_update( xi_context, &feed );
+        printf( "done...\n" );
+        wait( 1.0 );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xi_user_config.h	Sat Nov 09 01:02:05 2013 +0000
@@ -0,0 +1,23 @@
+#ifndef __XI_USER_CONFIG_H__
+#define __XI_USER_CONFIG_H__
+
+// The following settings should lower memory footprint.
+// The library currently allows one to send batch datapoint
+// and feed updates, but it's not needed in most use cases
+#define XI_MAX_DATAPOINTS         1
+// The number of channels can be increased if needed
+#define XI_MAX_DATASTREAMS        5
+
+// Below are optimisations that reduce some minor functionality
+#define XI_OPT_NO_ERROR_STRINGS
+
+// If you wish to enable assertions, set this to 1
+#define XI_DEBUG_ASSERT 0
+// If you wish to disable debug output, set this to 0
+#define XI_DEBUG_OUTPUT 0
+
+// On the mbed app board we can use the LCD for debug output,
+// but one may wish to modify this and write to file instead
+#define XI_DEBUG_PRINTF printf
+
+#endif /* __XI_USER_CONFIG_H__ */