Usage example, Xively with wolfSSL
Dependencies: EthernetInterface HTTPClient SDFileSystem mbed-rtos mbed wolfSSL
Fork of SimpleXively by
main.cpp@2:74161080023f, 2015-07-21 (annotated)
- Committer:
- wolfSSL
- Date:
- Tue Jul 21 23:16:48 2015 +0000
- Revision:
- 2:74161080023f
- Parent:
- 1:60e6225ef3e5
Initial public version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 0:a6ee4ada0d57 | 1 | /* main.cpp |
wolfSSL | 0:a6ee4ada0d57 | 2 | * |
wolfSSL | 0:a6ee4ada0d57 | 3 | * Copyright (C) 2006-2014 wolfSSL Inc. |
wolfSSL | 0:a6ee4ada0d57 | 4 | * |
wolfSSL | 0:a6ee4ada0d57 | 5 | * This file is part of CyaSSL. |
wolfSSL | 0:a6ee4ada0d57 | 6 | * |
wolfSSL | 0:a6ee4ada0d57 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
wolfSSL | 0:a6ee4ada0d57 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 0:a6ee4ada0d57 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 0:a6ee4ada0d57 | 10 | * (at your option) any later version. |
wolfSSL | 0:a6ee4ada0d57 | 11 | * |
wolfSSL | 0:a6ee4ada0d57 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
wolfSSL | 0:a6ee4ada0d57 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 0:a6ee4ada0d57 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 0:a6ee4ada0d57 | 15 | * GNU General Public License for more details. |
wolfSSL | 0:a6ee4ada0d57 | 16 | * |
wolfSSL | 0:a6ee4ada0d57 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 0:a6ee4ada0d57 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 0:a6ee4ada0d57 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
wolfSSL | 0:a6ee4ada0d57 | 20 | */ |
wolfSSL | 0:a6ee4ada0d57 | 21 | |
wolfSSL | 0:a6ee4ada0d57 | 22 | #include "mbed.h" |
wolfSSL | 0:a6ee4ada0d57 | 23 | #include "EthernetInterface.h" |
wolfSSL | 0:a6ee4ada0d57 | 24 | #include "HTTPClient.h" |
wolfSSL | 0:a6ee4ada0d57 | 25 | |
wolfSSL | 2:74161080023f | 26 | #include <SDFileSystem.h> |
wolfSSL | 2:74161080023f | 27 | SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd"); |
wolfSSL | 0:a6ee4ada0d57 | 28 | |
wolfSSL | 0:a6ee4ada0d57 | 29 | #define BUFFSIZE (50+1) |
wolfSSL | 0:a6ee4ada0d57 | 30 | |
wolfSSL | 0:a6ee4ada0d57 | 31 | extern void xively_main(char *feed_id, char *api_key, char *ch_name) ; |
wolfSSL | 0:a6ee4ada0d57 | 32 | |
wolfSSL | 0:a6ee4ada0d57 | 33 | extern HTTPClient http; |
wolfSSL | 0:a6ee4ada0d57 | 34 | EthernetInterface eth; |
wolfSSL | 0:a6ee4ada0d57 | 35 | |
wolfSSL | 0:a6ee4ada0d57 | 36 | void thread_main(void const *av) |
wolfSSL | 0:a6ee4ada0d57 | 37 | { |
wolfSSL | 0:a6ee4ada0d57 | 38 | int i ; |
wolfSSL | 0:a6ee4ada0d57 | 39 | char ch_name[BUFFSIZE] ; |
wolfSSL | 2:74161080023f | 40 | FILE *fp ; |
wolfSSL | 2:74161080023f | 41 | char id[BUFFSIZE], key[BUFFSIZE] ; |
wolfSSL | 2:74161080023f | 42 | |
wolfSSL | 2:74161080023f | 43 | fp = fopen("/sd/XivelyKey.txt", "r"); |
wolfSSL | 2:74161080023f | 44 | if (fp == NULL) { |
wolfSSL | 2:74161080023f | 45 | printf("Cannot open \"XivelyKey.txt\"\n") ; |
wolfSSL | 0:a6ee4ada0d57 | 46 | return ; |
wolfSSL | 0:a6ee4ada0d57 | 47 | } |
wolfSSL | 2:74161080023f | 48 | fgets(id, sizeof(id), fp) ; |
wolfSSL | 2:74161080023f | 49 | if((id[strlen(id)-2] == '\n')||(id[strlen(id)-2] == '\r'))id[strlen(id)-2] = '\0' ; |
wolfSSL | 2:74161080023f | 50 | fgets(key, sizeof(key), fp) ; |
wolfSSL | 2:74161080023f | 51 | if((key[strlen(key)-2] == '\n')||(key[strlen(key)-2] == '\r'))key[strlen(key)-2] = '\0' ; |
wolfSSL | 2:74161080023f | 52 | printf("ID=%s\nKey=%s\n",id, key) ; |
wolfSSL | 0:a6ee4ada0d57 | 53 | |
wolfSSL | 0:a6ee4ada0d57 | 54 | printf("Channel Name:") ; |
wolfSSL | 0:a6ee4ada0d57 | 55 | for(i=0; i<BUFFSIZE; i++) { |
wolfSSL | 0:a6ee4ada0d57 | 56 | if((ch_name[i] = getchar()) == '\r') { |
wolfSSL | 0:a6ee4ada0d57 | 57 | ch_name[i] = '\0' ; |
wolfSSL | 0:a6ee4ada0d57 | 58 | putchar('\n') ; |
wolfSSL | 0:a6ee4ada0d57 | 59 | break ; |
wolfSSL | 0:a6ee4ada0d57 | 60 | } else putchar(ch_name[i]) ; |
wolfSSL | 0:a6ee4ada0d57 | 61 | } |
wolfSSL | 0:a6ee4ada0d57 | 62 | |
wolfSSL | 2:74161080023f | 63 | xively_main(id, key, ch_name) ; |
wolfSSL | 0:a6ee4ada0d57 | 64 | |
wolfSSL | 0:a6ee4ada0d57 | 65 | while (true) { |
wolfSSL | 0:a6ee4ada0d57 | 66 | Thread::wait(1000); |
wolfSSL | 0:a6ee4ada0d57 | 67 | } |
wolfSSL | 0:a6ee4ada0d57 | 68 | } |
wolfSSL | 0:a6ee4ada0d57 | 69 | |
wolfSSL | 0:a6ee4ada0d57 | 70 | int main() { |
wolfSSL | 0:a6ee4ada0d57 | 71 | int ret ; |
wolfSSL | 0:a6ee4ada0d57 | 72 | |
wolfSSL | 0:a6ee4ada0d57 | 73 | ret = eth.init(); //Use DHCP |
wolfSSL | 0:a6ee4ada0d57 | 74 | printf("Xively Starting,...\n") ; |
wolfSSL | 0:a6ee4ada0d57 | 75 | |
wolfSSL | 0:a6ee4ada0d57 | 76 | while(1) { |
wolfSSL | 0:a6ee4ada0d57 | 77 | ret = eth.connect(); |
wolfSSL | 0:a6ee4ada0d57 | 78 | if(ret == 0)break ; |
wolfSSL | 0:a6ee4ada0d57 | 79 | Thread::wait(100); |
wolfSSL | 0:a6ee4ada0d57 | 80 | } |
wolfSSL | 0:a6ee4ada0d57 | 81 | printf("IP = %s\n", eth.getIPAddress()); |
wolfSSL | 0:a6ee4ada0d57 | 82 | |
wolfSSL | 0:a6ee4ada0d57 | 83 | #define STACK_SIZE 20000 |
wolfSSL | 0:a6ee4ada0d57 | 84 | Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE); |
wolfSSL | 0:a6ee4ada0d57 | 85 | |
wolfSSL | 0:a6ee4ada0d57 | 86 | while(1) |
wolfSSL | 0:a6ee4ada0d57 | 87 | Thread::wait(1000) ; |
wolfSSL | 0:a6ee4ada0d57 | 88 | } |