Dreameforce 2013 giveaway demo

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

Committer:
errordeveloper
Date:
Sat Nov 09 10:15:50 2013 +0000
Revision:
14:1bb008e28de8
Parent:
11:bdf601a405fc
Child:
15:7443df31ff5b
Initial WIP...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xively 0:efdea27c3b81 1 #include "mbed.h"
xively 0:efdea27c3b81 2 #include "EthernetInterface.h"
xively 7:0eff5db44b8b 3
errordeveloper 14:1bb008e28de8 4 #define XI_FEED_ID 34525050 // set Xively Feed ID (numerical, no quoutes)
errordeveloper 14:1bb008e28de8 5 #define XI_API_KEY "MsBCnO8YoVNiDBt3X1WbO5MkxO3No2hzMNx45OwbeHf5CecZ" // set Xively API key (double-quoted string)
errordeveloper 10:86ffba646df1 6
errordeveloper 10:86ffba646df1 7 #include "app_board_io.h"
xively 7:0eff5db44b8b 8
xively 0:efdea27c3b81 9 #include "xively.h"
xively 0:efdea27c3b81 10 #include "xi_err.h"
xively 0:efdea27c3b81 11
errordeveloper 10:86ffba646df1 12 #include "MMA7660.h"
errordeveloper 10:86ffba646df1 13 #include "LM75B.h"
errordeveloper 11:bdf601a405fc 14 #include "C12832_lcd.h"
errordeveloper 10:86ffba646df1 15
xively 3:7ad3f6543b6e 16 LM75B tmp(p28, p27);
errordeveloper 11:bdf601a405fc 17 C12832_LCD lcd;
errordeveloper 11:bdf601a405fc 18
errordeveloper 11:bdf601a405fc 19 #include "logo.h"
xively 0:efdea27c3b81 20
xively 0:efdea27c3b81 21 int main() {
errordeveloper 11:bdf601a405fc 22 lcd_print_xively_logo();
xively 0:efdea27c3b81 23 EthernetInterface eth;
xively 0:efdea27c3b81 24
xively 0:efdea27c3b81 25 int s = eth.init(); //Use DHCP
xively 0:efdea27c3b81 26
xively 0:efdea27c3b81 27 if( s != NULL )
xively 0:efdea27c3b81 28 {
xively 7:0eff5db44b8b 29 lcd_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 30 exit( 0 );
xively 0:efdea27c3b81 31 }
xively 0:efdea27c3b81 32
xively 0:efdea27c3b81 33 s = eth.connect();
xively 0:efdea27c3b81 34
xively 0:efdea27c3b81 35 if( s != NULL )
xively 0:efdea27c3b81 36 {
xively 7:0eff5db44b8b 37 lcd_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 38 exit( 0 );
xively 0:efdea27c3b81 39 }
xively 0:efdea27c3b81 40 else
xively 0:efdea27c3b81 41 {
xively 7:0eff5db44b8b 42 lcd_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 43 }
xively 0:efdea27c3b81 44
errordeveloper 14:1bb008e28de8 45 xi_feed_t output_channels;
errordeveloper 14:1bb008e28de8 46 memset( &output_channels, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 47
errordeveloper 14:1bb008e28de8 48 output_channels.feed_id = XI_FEED_ID;
errordeveloper 14:1bb008e28de8 49 output_channels.datastream_count = 1;
errordeveloper 14:1bb008e28de8 50
errordeveloper 14:1bb008e28de8 51 output_channels.datastreams[0].datapoint_count = 1;
errordeveloper 14:1bb008e28de8 52 xi_datastream_t* temperature_datastream = &output_channels.datastreams[0];
errordeveloper 14:1bb008e28de8 53 strcpy( temperature_datastream->datastream_id, "temp" );
errordeveloper 14:1bb008e28de8 54 xi_datapoint_t* temp = &temperature_datastream->datapoints[0];
xively 0:efdea27c3b81 55
errordeveloper 14:1bb008e28de8 56 xi_feed_t input_channels;
errordeveloper 14:1bb008e28de8 57 memset( &input_channels, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 58
errordeveloper 14:1bb008e28de8 59 input_channels.feed_id = XI_FEED_ID;
errordeveloper 14:1bb008e28de8 60 input_channels.datastream_count = 2;
xively 0:efdea27c3b81 61
errordeveloper 14:1bb008e28de8 62 input_channels.datastreams[0].datapoint_count = 1;
errordeveloper 14:1bb008e28de8 63 xi_datastream_t* fan_ctl_datastream = &input_channels.datastreams[0];
errordeveloper 14:1bb008e28de8 64 strcpy( fan_ctl_datastream->datastream_id, "fan" );
errordeveloper 14:1bb008e28de8 65 xi_datapoint_t* fan_ctl = &fan_ctl_datastream->datapoints[0];
errordeveloper 14:1bb008e28de8 66
errordeveloper 14:1bb008e28de8 67 input_channels.datastreams[1].datapoint_count = 1;
errordeveloper 14:1bb008e28de8 68 xi_datastream_t* led_ctl_datastream = &input_channels.datastreams[1];
errordeveloper 14:1bb008e28de8 69 strcpy( led_ctl_datastream->datastream_id, "led" );
errordeveloper 14:1bb008e28de8 70 xi_datapoint_t* led_ctl = &led_ctl_datastream->datapoints[0];
xively 3:7ad3f6543b6e 71
xively 0:efdea27c3b81 72 // create the cosm library context
xively 0:efdea27c3b81 73 xi_context_t* xi_context
errordeveloper 14:1bb008e28de8 74 = xi_create_context( XI_HTTP, XI_API_KEY, output_channels.feed_id );
xively 0:efdea27c3b81 75
xively 0:efdea27c3b81 76 // check if everything works
xively 0:efdea27c3b81 77 if( xi_context == NULL )
xively 0:efdea27c3b81 78 {
xively 0:efdea27c3b81 79 return -1;
xively 0:efdea27c3b81 80 }
xively 0:efdea27c3b81 81
xively 0:efdea27c3b81 82 while(1) {
xively 0:efdea27c3b81 83
errordeveloper 14:1bb008e28de8 84 xi_set_value_f32( temp, tmp.read() );
errordeveloper 14:1bb008e28de8 85
errordeveloper 14:1bb008e28de8 86 printf( "Updating output channels...\r\n" );
errordeveloper 14:1bb008e28de8 87 xi_feed_update( xi_context, &output_channels );
errordeveloper 14:1bb008e28de8 88 printf( " [%s]\r\n", xi_get_error_string( xi_get_last_error() ) );
errordeveloper 14:1bb008e28de8 89
errordeveloper 14:1bb008e28de8 90 printf( "Reading input channels...\r\n" );
errordeveloper 14:1bb008e28de8 91 xi_feed_get( xi_context, &input_channels );
errordeveloper 14:1bb008e28de8 92 printf( " [%s]\r\n", xi_get_error_string( xi_get_last_error() ) );
xively 0:efdea27c3b81 93
errordeveloper 14:1bb008e28de8 94 if( strcmp( xi_value_pointer_str( led_ctl ), "RED" ) == 0 )
errordeveloper 14:1bb008e28de8 95 {
errordeveloper 14:1bb008e28de8 96 lcd_printf( "Turning LED red\n" );
errordeveloper 14:1bb008e28de8 97 }
errordeveloper 14:1bb008e28de8 98 else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 )
errordeveloper 14:1bb008e28de8 99 {
errordeveloper 14:1bb008e28de8 100 lcd_printf( "Turning LED green\n" );
xively 0:efdea27c3b81 101 }
errordeveloper 14:1bb008e28de8 102 else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 )
errordeveloper 14:1bb008e28de8 103 {
errordeveloper 14:1bb008e28de8 104 lcd_printf( "Turning LED blue\n" );
errordeveloper 14:1bb008e28de8 105 }
errordeveloper 14:1bb008e28de8 106 else /* OFF */
errordeveloper 14:1bb008e28de8 107 {
errordeveloper 14:1bb008e28de8 108 lcd_printf( "Turning off the LED\n" );
errordeveloper 14:1bb008e28de8 109 }
xively 3:7ad3f6543b6e 110
xively 3:7ad3f6543b6e 111 wait( 15.0 );
xively 0:efdea27c3b81 112 }
Ilya Dmitrichenko 6:9e4f4a8c1829 113 }