Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf NTPClient_NetServices mbed ConfigFile
pachube.c
00001 /************************************************************* 00002 00003 pachube.c 00004 00005 *************************************************************/ 00006 #include "PachubeV2CSV.h" 00007 #include "TextLCD.h" 00008 #include "appconf.h" 00009 #define PACHUBE_CODE_OK 200 00010 #define CONFIG_FILENAME "/local/PACHUBE.CFG" 00011 00012 extern float uSv; 00013 extern float cpm; 00014 extern TextLCD lcd; 00015 extern int mode; 00016 extern appconf_t appconf; 00017 extern float long_cpm; 00018 extern float long_uSv; 00019 00020 void convertDoubleToChar(double val, char *buf, size_t bufsiz) { 00021 snprintf(buf, bufsiz, "%f", val); 00022 } 00023 00024 void pachube_setup(appconf_t *appconf){ 00025 lcd.cls(); 00026 lcd.locate(0, 0); 00027 lcd.printf("cfg file Reading..."); 00028 lcd.locate(0, 1); 00029 lcd.printf("Setup: "); 00030 appconf_init(appconf); 00031 if (appconf_read(CONFIG_FILENAME, appconf) != 0) { 00032 lcd.printf("[NG]"); 00033 error("Failure to read a configuration file.\n"); 00034 } 00035 else{ 00036 lcd.printf("[OK]"); 00037 wait(1); 00038 } 00039 printf("pachube apikey %s\n",appconf->apikey); 00040 } 00041 00042 int web_post(PachubeV2CSV *web, int feed_id, int stream_no, double value, HTTPClient *pClient) { 00043 char value_text[16]; 00044 convertDoubleToChar(value, value_text, sizeof(value_text)); 00045 char stream_no_text[8]; 00046 stream_no_text[0] = "0123456789"[stream_no]; 00047 stream_no_text[1] = '\0'; 00048 return web->updateDataStream(feed_id, stream_no_text, std::string(value_text), pClient); 00049 00050 } 00051 00052 void pachube_output(PachubeV2CSV* web, HTTPClient *pClient){ 00053 int feed_id = atoi(appconf.feedid); 00054 00055 if (appconf.stream_nsv0 >= 0) { 00056 if (web_post(web, feed_id, appconf.stream_nsv0,(double)uSv*1000, pClient) != PACHUBE_CODE_OK) { 00057 lcd.printf("Checking Pachube status:x"); 00058 printf("upload failed -stream1 \n"); 00059 wait(3); 00060 } else { 00061 printf("upload -stream1 \r\n"); 00062 } 00063 } 00064 00065 if (appconf.stream_cpm0 >= 0) { 00066 if (web_post(web, feed_id, appconf.stream_cpm0, (double)cpm, pClient) != PACHUBE_CODE_OK){ 00067 lcd.printf("Checking Pachube status:x"); 00068 printf("upload failed -stream2 \n"); 00069 wait(3); 00070 } else { 00071 printf("upload -stream2 \r\n"); 00072 } 00073 } 00074 00075 if (appconf.stream_nsvlong0 >= 0) { 00076 if (web_post(web, feed_id, appconf.stream_nsvlong0, (double)long_uSv*1000, pClient) != PACHUBE_CODE_OK){ // 2011/08/23 00077 lcd.printf("Checking Pachube status:x"); 00078 printf("upload failed -stream3 \n"); 00079 wait(3); 00080 } else { 00081 printf("upload -stream3 \r\n"); 00082 } 00083 } 00084 if (appconf.stream_cpmlong0 >= 0) { 00085 if (web_post(web, feed_id, appconf.stream_cpmlong0, (double)long_cpm, pClient) != PACHUBE_CODE_OK){ // 2011/08/23 00086 lcd.printf("Checking Pachube status:x"); 00087 printf("upload failed -stream4 \n"); 00088 wait(3); 00089 } else { 00090 printf("upload -stream4 \r\n"); 00091 } 00092 } 00093 }
Generated on Tue Jul 12 2022 10:57:43 by
1.7.2