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: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
main.cpp
00001 /* -------------------------------------------------------------------------- 00002 // update 01/01/2021: remove ethernet calls : ok 00003 // 00004 // update 30/12 update libs 00005 // 00006 // test compile ok 31/07/2020 00007 00008 // 01/09/2020 : update JPA serial et CAN : tests OK sur CAN et 1 srial 2 00009 : attention 1 seul serial operationnel serial 2 - serial 7 ne marche pas en reception 00010 // : test ok send/receive tasmota sur serial 2 00011 // 30/08/2020 : emission CAN OK en Wifi sur tasmota ou udp bridge 00012 // mais pb reception caracteres sur port serie ( idem port series pc ouu serial 7 00013 00014 // 02/08/2020 00015 // add sd parameters: read ok 00016 192.168.1.30 00017 0;Ethernet 00018 1;WiFi 00019 1;can 00020 1;serial 00021 F;Fonction 00022 0;Touche1 status : off 00023 0xFF00FF00;Touche1 BackColor 00024 0xFF000000;Touche1 TextColor 00025 Pompe ; Touche1 text 00026 Piscine ; Touche1 text1 00027 1;Touche2 Status : off 00028 0xFFFF0000; Touche2 BackColor 00029 0xFFFFFFFF; Touche2 TextColor 00030 Eclair ;Touche2 text 00031 Piscine ;Touche2 text1 00032 0; Touche3 Status : off 00033 0xFF00FF00; Touche3 BackColor 00034 0xFFFFFF00; Touche3 TextColor 00035 Leds Bl ;Touche3 text 00036 Piscine ; Touche3 text1 00037 1; Touche4 Status : off 00038 0xFF800000; Touche4 BackColor 00039 0xFFFFFF00; Touche4 TextColor 00040 Porche ; Touche4 text 00041 entree ; Touche4 text1 00042 Temp Piscine ; Temp1 text 00043 0xFF404040; backColorTemp1 00044 0xFFFFFF00; txtColorTemp1 00045 Temp Exterieur ; Temp2 text 00046 0xFF404040; backColorTemp2 00047 0xFFFFFF00; txtColorTemp2 00048 00049 // works ok 31/07/2020 00050 // updated package from jpa 00051 // added fonts in bsp_disco_f746ng/utilities/fonts 00052 // fonts.h updated to manage added fonts 00053 // grovestream.cpp & grovesttream.h updated 00054 // remove stm32746ng_dicovery_sd in /bsp_disco_f746ng/drivers/stm32746ng_discovery 00055 // mainSDAcardJPA issue: add sdcardjpa.cpp in lib /sdfilesystem_warning_fixed 00056 // isue with big fonts: replace /bsp_disco_f746ng/drivers/stm32746ng-discovery/stm32746ng-discovery_lcd.c &.h 00057 00058 // need to add CAN and WiFi 00059 00060 STM32F746 GroveStreams Stream Feed via Ethernet 00061 This GroveStreams example is designed for the STM32F746. 00062 https://www.grovestreams.com/developers/getting_started_stm32F746.html 00063 The STM32 uses DHCP and DNS for a simpler network setup. 00064 */ 00065 00066 #if !FEATURE_LWIP 00067 #error [NOT_SUPPORTED] LWIP not supported for this target 00068 #endif 00069 00070 #include "mbed.h" 00071 #include "LcdDiscoF746NgTracer.h" 00072 // #include "GroveStreams.h" 00073 #include "MbedJSONValue.h" 00074 #include "stm32746g_discovery_lcd.h" 00075 #include "stm32746g_discovery_ts.h" 00076 #include "CANMsg.h" 00077 //#include "ManageBufferJPA.h" 00078 #include "main.h" 00079 00080 extern char textButton[5][8]; 00081 extern char text1Button[5][8]; 00082 extern char textTempTitle[3][30]; 00083 extern uint32_t backColorButton[5], txtColorButton[5]; 00084 extern char statusButton[5][30]; 00085 00086 //#include "touchScreen.cpp" 00087 int touchInitJPA1(); // from touchScreenJPA.cpp 00088 int touchJPA1(); // from touchScreenJPA.cpp 00089 int touchInitGuiJPA1(); // from touchScreenJPA.cpp 00090 int sendTouchJPA(int xx); // from touchScreenJPA.cpp 00091 time_t lastToucheTime = 0; 00092 int touchButtonJPA1(int numButton); // from touchScreenJPa.cpp 00093 00094 //#include "GuiJPA.cpp" 00095 int initDisplayTemp(); 00096 int initDatasGuiJPA(); 00097 int setTemp1(std::string temp1); 00098 int setTemp2(std::string temp2); 00099 int sendInitDatasJPA(int xx); 00100 int timer_lcd_on = 0; 00101 00102 //#SDCARD 00103 int mainSDCardJPA(); //in sdcardjpa.cpp in lib /sdfilesystem_warning_fixedd 00104 00105 //GroveStreams Stream IDs. Stream IDs tell GroveStreams which component streams the values will be assigned to. 00106 //Don't change these unless you edit your GroveStreams component definition and change the stream IDs to match these. 00107 const char gsStreamId1[] = "voltage"; 00108 const char gsStreamId2[] = "temperature"; 00109 char gsStreamIPdatas[] = "192.168.1.49"; 00110 int ethernet_actif = '0'; 00111 int wifi_actif = '1'; 00112 int can_actif = '1'; 00113 int serial_actif = '1'; 00114 char read_sd[] = ""; 00115 char function_mod[]= "O"; 00116 00117 char touch1_status[]= "0"; 00118 char touch1_back_color[]= "0xFF404040"; 00119 char touch1_text_color[]= "0xFFFFFF00"; 00120 char touch1_text[]= "Touch1"; 00121 char touch1_text1[]= "Text1"; 00122 00123 char touch2_status[]= "0"; 00124 char touch2_back_color[]= "0xFF404040"; 00125 char touch2_text_color[]= "0xFFFFFF00"; 00126 char touch2_text[]= "Touch2"; 00127 char touch2_text1[]= "Text2"; 00128 00129 char touch3_status[]= "0"; 00130 char touch3_back_color[]= "0xFF404040"; 00131 char touch3_text_color[]= "0xFFFFFF00"; 00132 char touch3_text[]= "Touch3"; 00133 char touch3_text1[]= "Text3"; 00134 00135 char touch4_status[]= "0"; 00136 char touch4_back_color[]= "0xFF404040"; 00137 char touch4_text_color[]= "0xFFFFFF00"; 00138 char touch4_text[]= "Touch4"; 00139 char touch4_text1[]= "Text4"; 00140 00141 char temp1_text[]= "Temp1"; 00142 char temp1_back_color[]= "0xFF404040"; 00143 char temp1_text_color[]= "0xFFFFFF00"; 00144 00145 char temp2_text[]= "Temp2"; 00146 char temp2_back_color[]= "0xFF404040"; 00147 char temp2_text_color[]= "0xFFFFFF00"; 00148 00149 00150 00151 int len_line_sd = 0; 00152 00153 uint8_t text2[30]; 00154 uint8_t counter = 0; 00155 float voltage; 00156 00157 Timer timer; 00158 extern Timer timer_lcd; 00159 AnalogIn analogIn(A0); 00160 00161 // CAN ------------------------------------------------------------ 00162 CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name 00163 CANMsg rxMsg; 00164 CANMsg txMsg; 00165 00166 // Other Settings 00167 int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency. 00168 00169 AnalogIn adc_temp(ADC_TEMP); 00170 AnalogIn adc_vref(ADC_VREF); 00171 DigitalOut myled(LED1); 00172 00173 void initSerial(); 00174 void sendSerialUSB(char * str); 00175 void receiveSerialUSB(); 00176 void sendSerial2(char * str); 00177 void receiveSerial2(); 00178 void sendSerial7(char * str); 00179 void receiveSerial7(); 00180 00181 //extern volatile char bufferSerialUSB[]; 00182 extern volatile int msgSerialUSB; 00183 extern char stringSerialUSB[]; // trame from serialUSB 00184 extern int stringSerialUSBok; // si ==1 alors trame dispo (fin de trame == LF ou 10 00185 00186 extern volatile int msgSerial2; 00187 extern char stringSerial2[]; // trame from serialUSB 00188 extern int stringSerial2ok; // si ==1 alors trame dispo (fin de trame == LF ou 10 00189 00190 extern volatile int msgSerial7; 00191 extern char stringSerial7[]; // trame from serialUSB 00192 extern int stringSerial7ok; // si ==1 alors trame dispo (fin de trame == LF ou 10 00193 00194 //extern Serial serialUSB(USBTX, USBRX); // serial PC 00195 //extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge 00196 //extern Serial serial7(PF_7, PF_6); // TX, RX for extension 00197 00198 #define BOARD1 1 // comment out this line when compiling for board #2 00199 const unsigned int RX_ID = 0x101; 00200 const unsigned int TX_ID = 0x100; 00201 00202 00203 // --------------------------------------------------------------------------------------- 00204 //* @brief Prints CAN message to PC's serial terminal 00205 void printMsg(CANMessage& msg, int dir) 00206 { if (dir ==0) 00207 { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE); 00208 printf(" Can message sent : "); 00209 printf("ID = 0x%.3X Data=", msg.id); 00210 for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); 00211 printf("\n"); 00212 } 00213 else 00214 { printf(" Can message receive : "); 00215 /* 00216 printf(" ID = 0x%.3X\r\n", msg.id); 00217 printf(" Type = %d\r\n", msg.type); 00218 printf(" Format = %d\r\n", msg.format); 00219 printf(" Length = %d\r\n", msg.len); 00220 */ 00221 printf("ID = 0x%.3X Data=", msg.id); 00222 for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); 00223 printf("\n"); 00224 } 00225 } 00226 00227 /** ----------------------------------------------------------------------------------------- 00228 * @brief Handles received CAN messages 00229 * @note Called on 'CAN message received' interrupt. 00230 */ 00231 int CanRcv = 0; 00232 void onCanReceived(void) 00233 { can.read(rxMsg); 00234 CanRcv = 1; 00235 } 00236 00237 // ------------------------------------------------------------------------------------------ 00238 int main() 00239 { initSerial(); 00240 // attach ISR to handle received messages 00241 timer.start(); // start timer 00242 timer_lcd.start(); // start timer lcd off 00243 timer_lcd_on = 1; 00244 sendSerialUSB("CAN_Hello board serialUSB #1\r\n"); 00245 sendSerial2("CAN_Hello board serial2 #1\r\n"); 00246 sendSerial7("CAN_Hello board serial7 #1\r\n"); 00247 printf("\nInit SDCard ...\n"); 00248 mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib 00249 // reaf following datas 00250 // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters 00251 // store local variables from sd 00252 // gsStreamIPdatas[]; 00253 // ethernet_actif[] ; wifi_actif[];can_actif[]; serial_actif[]; function_mod[]= "O"; 00254 // touch1_status[]= "0"; touch1_back_color[]= "0xFF404040"; touch1_text_color[]= "0xFFFFFF00"; touch1_text[]= "Touch1"; touch1_text1[]= "Text1"; 00255 // touch2_status[]= "0"; touch2_back_color[]= "0xFF404040"; touch2_text_color[]= "0xFFFFFF00"; touch2_text[]= "Touch2"; touch2_text1[]= "Text2"; 00256 // touch3_status[]= "0"; touch3_back_color[]= "0xFF404040"; touch3_text_color[]= "0xFFFFFF00"; touch3_text[]= "Touch3"; touch3_text1[]= "Text3"; 00257 // touch4_status[]= "0"; touch4_back_color[]= "0xFF404040"; touch4_text_color[]= "0xFFFFFF00"; touch4_text[]= "Touch4"; touch4_text1[]= "Text4"; 00258 // temp1_text[]= "Temp1"; temp1_back_color[]= "0xFF404040"; temp1_text_color[]= "0xFFFFFF00"; 00259 // temp2_text[]= "Temp2"; temp2_back_color[]= "0xFF404040"; temp2_text_color[]= "0xFFFFFF00"; 00260 00261 printf("\nFin init SDCard ...\n"); 00262 BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD 00263 uint8_t text[300]; 00264 printf("Start Prog\n"); 00265 std::string temp1; 00266 std::string temp2; 00267 00268 //lastSuccessfulUploadTime is used for upload frequency. 00269 time_t lastSuccessfulUploadTime = 0; 00270 printf("\n Init touchJPA1 ...\n"); 00271 int yy; 00272 printf("\n Init initDisplayTemp ...\n"); 00273 yy = initDisplayTemp(); // from guijpa.cpp - Init display 00274 printf("\ninit touchInitJPA1 ...\n"); 00275 yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen 00276 yy = touchInitGuiJPA1(); // from touchscreen.cpp - display buttons 00277 printf("\ninit initDatasGuiJPA ...\n"); 00278 yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons - ethernet connection 00279 ////lcd.printf("Starting..."); 00280 printf("Starting...\n"); 00281 lastToucheTime = time(NULL); 00282 char data[5]; 00283 00284 // config can -------------------------------------- 00285 can.frequency(125000); // set CAN bit rate to 125 kbps 00286 //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID 00287 can.attach(onCanReceived, CAN::RxIrq); 00288 00289 BSP_LCD_DisplayOff(); 00290 BSP_LCD_DisplayOn(); 00291 //BSP_LCD_SetBackColor(LCD_COLOR_RED); 00292 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00293 BSP_LCD_SetBackColor(LCD_COLOR_RED); 00294 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00295 00296 // main loop --------------------------------------------------- 00297 while (true) { 00298 if (CanRcv > 0) // message CAN received --------------------- 00299 { CanRcv = 0; 00300 printMsg(rxMsg,1); 00301 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE); 00302 if (rxMsg.id == RX_ID) 00303 { rxMsg >> counter; 00304 rxMsg >> voltage; 00305 //serialUSB.printf(" counter = %d\r\n", counter); 00306 //serialUSB.printf(" voltage = %e V\r\n", voltage); 00307 } 00308 } 00309 if (msgSerialUSB > 0) {receiveSerialUSB();} // serial USB message received ---------------- 00310 if (stringSerialUSBok == 1) {printf("Trame SerialUSB : %s",stringSerialUSB);stringSerialUSBok=0;} 00311 00312 if (msgSerial2 > 0) {receiveSerial2();} // serial bridge message received ----------------- 00313 if (stringSerial2ok == 1) 00314 { printf("Trame Serial2 : %s",stringSerial2); 00315 stringSerial2ok=0; 00316 // decodage json datas 00317 // trame reçue : {"Temp1":"25","Temp2":"30"} 00318 char resultBuffer[100]= {0}; 00319 //resultBuffer = stringSerial2; 00320 //if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') 00321 if (strlen(stringSerial2) > 0 && stringSerial2[0] == '{') 00322 { MbedJSONValue mbedJson; //parse(mbedJson, resultBuffer); 00323 parse(mbedJson, stringSerial2); 00324 sprintf((char*)text, "HTTP string : %s\n", stringSerial2); 00325 if (mbedJson.hasMember("Temp1")) 00326 { printf("Serial2 temp1: %s",stringSerial2); 00327 int pp = setTemp1(mbedJson["Temp1"].get<std::string>()); // display temp1 on lcd 00328 } 00329 if (mbedJson.hasMember("Temp2")) 00330 { int tt=setTemp2(mbedJson["Temp2"].get<std::string>()); 00331 } 00332 // add buttons parameters 00333 // decode button trame 00334 if (mbedJson.hasMember("Touche4")) 00335 { printf("Touche 4 update status received"); 00336 string s; 00337 s = mbedJson["Touche4"]["Status"].get<std::string>(); 00338 sprintf(statusButton[4],s.c_str()); 00339 printf(s.c_str()); 00340 printf("\n"); 00341 if (s=="on") 00342 { txtColorButton[4] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00343 backColorButton[4] = (uint32_t)strtoul("0xFF000000", NULL,16); 00344 } 00345 else 00346 { txtColorButton[4] = (uint32_t)strtoul("0xFF000000", NULL,16); 00347 backColorButton[4] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00348 } 00349 touchButtonJPA1(4); 00350 } 00351 if (mbedJson.hasMember("Touche1")) 00352 { printf("Touche 1 update status received"); 00353 string s; 00354 s = mbedJson["Touche1"]["Status"].get<std::string>(); 00355 sprintf(statusButton[1],s.c_str()); 00356 printf(s.c_str()); 00357 printf("\n"); 00358 if (s=="on") 00359 { txtColorButton[1] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00360 backColorButton[1] = (uint32_t)strtoul("0xFF000000", NULL,16); 00361 } 00362 else 00363 { txtColorButton[1] = (uint32_t)strtoul("0xFF000000", NULL,16); 00364 backColorButton[1] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00365 } 00366 touchButtonJPA1(1); 00367 } 00368 if (mbedJson.hasMember("Touche2")) 00369 { printf("Touche 2 update status received"); 00370 string s; 00371 s = mbedJson["Touche2"]["Status"].get<std::string>(); 00372 sprintf(statusButton[2],s.c_str()); 00373 printf(s.c_str()); 00374 printf("\n"); 00375 if (s=="on") 00376 { txtColorButton[2] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00377 backColorButton[2] = (uint32_t)strtoul("0xFF000000", NULL,16); 00378 } 00379 else 00380 { txtColorButton[2] = (uint32_t)strtoul("0xFF000000", NULL,16); 00381 backColorButton[2] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00382 } 00383 touchButtonJPA1(2); 00384 } 00385 if (mbedJson.hasMember("Touche3")) 00386 { printf("Touche 3 update status received"); 00387 string s; 00388 s = mbedJson["Touche3"]["Status"].get<std::string>(); 00389 sprintf(statusButton[3],s.c_str()); 00390 printf(s.c_str()); 00391 printf("\n"); 00392 if (s=="on") 00393 { txtColorButton[3] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00394 backColorButton[3] = (uint32_t)strtoul("0xFF000000", NULL,16); 00395 } 00396 else 00397 { txtColorButton[3] = (uint32_t)strtoul("0xFF000000", NULL,16); 00398 backColorButton[3] = (uint32_t)strtoul("0xFF00FF00", NULL,16); 00399 } 00400 touchButtonJPA1(3); 00401 } 00402 } 00403 } // end serial bridge message received ----------- 00404 if (msgSerial7 > 0) {receiveSerial7();}// serial7 message received - not working --------------- 00405 if (stringSerial7ok == 1) {printf("Trame Serial7 : %s",stringSerial7);stringSerial7ok=0;} 00406 00407 // timer lcd -------------------- 00408 if(timer_lcd.read() >= 1000) // check for timeout 00409 { timer_lcd.stop(); // stop the timer 00410 timer_lcd.reset(); // reset the timer 00411 timer_lcd_on =0; 00412 BSP_LCD_DisplayOff(); 00413 } 00414 // timer send can ------------------------ 00415 if(timer.read_ms() >= 10000) // check for timeout 00416 { timer.stop(); // stop the timer 00417 timer.reset(); // reset the timer 00418 counter = (counter+1) & 1; // increment the counter 00419 voltage = 0;////(analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input 00420 txMsg.clear(); // clear the Tx message storage 00421 txMsg.id = 0x100130CA;//TX_ID; // set the message ID 00422 txMsg.format = CANExtended ; //extended 00423 txMsg.len=2; 00424 txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!) 00425 if(can.write(txMsg)) // transmit message 00426 { //if(can->write(txMsg)) { // transmit the CAN message 00427 printf("TX CAN OK \n"); 00428 printMsg(txMsg,0); 00429 //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); 00430 //BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); 00431 } 00432 else 00433 { //serialUSB.printf("Transmission error\r\n"); 00434 printf("TX CAN Fail \n"); 00435 //BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); 00436 //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); 00437 } 00438 timer.start(); // insert transmission lag 00439 } // end if timer send can ------------------- 00440 // touch screen detection ------------------------------- 00441 int xx = touchJPA1(); // 00442 if (xx > 0) // touch detected 00443 { if (xx==9) // display pressed but not a touch 00444 { timer_lcd.stop(); // stop the timer 00445 timer_lcd.reset(); // reset the timer 00446 /////////BSP_LCD_DisplayOn(); 00447 } 00448 if (xx == 4) // touch 4 pressed 00449 { // send trame to can 00450 txMsg.id = 0x100130CB;//TX_ID; // set the message ID 00451 txMsg.format = CANExtended ; //extended 00452 txMsg.len=2; 00453 txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!) 00454 if(can.write(txMsg)) // transmit message 00455 { printMsg(txMsg,0); 00456 printf("TX CAN OK \n"); 00457 //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); 00458 //BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); 00459 } 00460 else 00461 { printf("TX CAN Fail \n"); 00462 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); 00463 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); 00464 } 00465 } 00466 xx = sendTouchJPA(xx); 00467 lastToucheTime = time(NULL); 00468 } 00469 else 00470 { lastToucheTime = 0; 00471 } // send mqtt 00472 // Update sensor data to GroveStreams 00473 time_t seconds = time(NULL); 00474 if(seconds - lastSuccessfulUploadTime > updateFrequency) { 00475 ////lcd.clear(); 00476 ////lcd.printf("Getting Samples..."); 00477 printf("Getting Samples...\n"); 00478 //Assemble the samples into URL parameters which are seperated with the "&" character 00479 // Example: &s1=6.2&s2=78.231 00480 int temperature = 0; //adc_temp.read() * 100.0f; 00481 int voltage = 0; //adc_vref.read() * 100.0f; 00482 char samples[64] = {0}; 00483 sprintf(samples, "&%s=%d&%s=%d", gsStreamId1, voltage, gsStreamId2, temperature); 00484 //Append on command requests (request stream values) 00485 //This will indicate to GroveStreams to return the last value 00486 // of each request stream during the sample upload 00487 strcat(samples, "&rsid=freq&rsid=led"); 00488 char resultBuffer[700]= {0}; 00489 //Sending Samples (and returning current command stream values) 00490 time_t connectAttemptTime = time(NULL); 00491 ///////// int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); //receive mqtt 00492 int sendResult = 0; 00493 if (sendResult == 0) { 00494 ////lcd.printf("Send Successful"); 00495 printf("Send Successful\n"); 00496 lastSuccessfulUploadTime = connectAttemptTime; 00497 //Handle command streams 00498 if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') { 00499 MbedJSONValue mbedJson; 00500 parse(mbedJson, resultBuffer); 00501 sprintf((char*)text, "HTTP string : %s\n", resultBuffer); 00502 //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE); 00503 if (mbedJson.hasMember("Temp1")) { 00504 int pp=setTemp1(mbedJson["Temp1"].get<std::string>()); 00505 } 00506 if (mbedJson.hasMember("Temp2")) { 00507 int tt=setTemp2(mbedJson["Temp2"].get<std::string>()); 00508 } 00509 if (mbedJson.hasMember("led")) { 00510 //Change LED 00511 myled = mbedJson["led"].get<bool>() ? 1 : 0; 00512 ////lcd.printf("LED: %s", mbedJson["led"].get<bool>() ? "On" : "Off"); 00513 printf("LED: %s\n", mbedJson["led"].get<bool>() ? "On" : "Off"); 00514 } 00515 } 00516 } 00517 } 00518 00519 } 00520 } 00521 00522
Generated on Wed Jul 13 2022 16:31:24 by
1.7.2