Usage example, Xively with wolfSSL

Dependencies:   EthernetInterface HTTPClient SDFileSystem mbed-rtos mbed wolfSSL

Fork of SimpleXively by wolf SSL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* main.cpp
00002  *
00003  * Copyright (C) 2006-2014 wolfSSL Inc.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 #include "mbed.h"
00023 #include "EthernetInterface.h"
00024 #include "HTTPClient.h"
00025 
00026 #include <SDFileSystem.h>
00027 SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd");
00028 
00029 #define BUFFSIZE (50+1)
00030 
00031 extern void xively_main(char *feed_id, char *api_key, char *ch_name) ;
00032 
00033 extern HTTPClient http;
00034 EthernetInterface eth;
00035 
00036 void thread_main(void const *av)
00037 {
00038     int i ;
00039     char ch_name[BUFFSIZE] ;
00040     FILE *fp ;
00041     char id[BUFFSIZE], key[BUFFSIZE] ;
00042     
00043     fp = fopen("/sd/XivelyKey.txt", "r");
00044     if (fp == NULL) {
00045         printf("Cannot open \"XivelyKey.txt\"\n") ;
00046         return ;
00047     }
00048     fgets(id, sizeof(id), fp) ; 
00049     if((id[strlen(id)-2] == '\n')||(id[strlen(id)-2] == '\r'))id[strlen(id)-2] = '\0' ;
00050     fgets(key, sizeof(key), fp) ; 
00051     if((key[strlen(key)-2] == '\n')||(key[strlen(key)-2] == '\r'))key[strlen(key)-2] = '\0' ;
00052     printf("ID=%s\nKey=%s\n",id, key) ;
00053     
00054     printf("Channel Name:") ;
00055     for(i=0; i<BUFFSIZE; i++) {
00056         if((ch_name[i] = getchar()) == '\r') {
00057             ch_name[i] = '\0' ;
00058             putchar('\n') ;
00059             break ;
00060         } else putchar(ch_name[i]) ;
00061     }
00062     
00063     xively_main(id, key, ch_name) ;
00064     
00065     while (true) {
00066         Thread::wait(1000);
00067     }
00068 }
00069 
00070 int main() {
00071     int ret ;
00072     
00073     ret = eth.init(); //Use DHCP
00074     printf("Xively Starting,...\n") ;
00075 
00076     while(1) {
00077         ret = eth.connect();
00078         if(ret == 0)break ;
00079         Thread::wait(100);
00080     }
00081     printf("IP = %s\n", eth.getIPAddress());
00082     
00083     #define STACK_SIZE 20000
00084     Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE);
00085 
00086     while(1)
00087         Thread::wait(1000) ;
00088 }