version with updated libs

Dependencies:   F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON

Committer:
jeanpierreaulas
Date:
Fri Sep 04 09:48:07 2020 +0000
Branch:
jpa
Revision:
7:6ec7a4b94d0b
Parent:
5:ceefd0cfa233
Child:
8:275ae4382788
cleaning code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
38domo 0:48863a0964f5 1 /* --------------------------------------------------------------------------
38domo 0:48863a0964f5 2 // test compile ok 31/07/2020
38domo 0:48863a0964f5 3
38domo 0:48863a0964f5 4 // 30/08/2020 : emission CAN OK en Wifi sur tasmota ou udp bridge
38domo 0:48863a0964f5 5 // mais pb reception caracteres sur port serie ( idem port series pc ouu serial 7
38domo 0:48863a0964f5 6
38domo 0:48863a0964f5 7 // 02/08/2020
38domo 0:48863a0964f5 8 // add sd parameters: read ok
38domo 0:48863a0964f5 9 // ip address
38domo 0:48863a0964f5 10 // ethernet actif
38domo 0:48863a0964f5 11 // wifi actif
38domo 0:48863a0964f5 12 // can actif
38domo 0:48863a0964f5 13 // serial actif
38domo 0:48863a0964f5 14 // fonction
38domo 0:48863a0964f5 15 // Touche1 status (0/1)
38domo 0:48863a0964f5 16 // Touche1 backcolor
38domo 0:48863a0964f5 17 // touche1 text color
38domo 0:48863a0964f5 18 // Touche1 text
38domo 0:48863a0964f5 19 // Touche1 text1
38domo 0:48863a0964f5 20 // Touche2
38domo 0:48863a0964f5 21 // Touche3
38domo 0:48863a0964f5 22 // Touche4
38domo 0:48863a0964f5 23 // Temp1 text
38domo 0:48863a0964f5 24 // Temp2 text
38domo 0:48863a0964f5 25
38domo 0:48863a0964f5 26 // works ok 31/07/2020
38domo 0:48863a0964f5 27 // updated package from jpa
38domo 0:48863a0964f5 28 // added fonts in bsp_disco_f746ng/utilities/fonts
38domo 0:48863a0964f5 29 // fonts.h updated to manage added fonts
38domo 0:48863a0964f5 30 // grovestream.cpp & grovesttream.h updated
38domo 0:48863a0964f5 31 // remove stm32746ng_dicovery_sd in /bsp_disco_f746ng/drivers/stm32746ng_discovery
38domo 0:48863a0964f5 32 // mainSDAcardJPA issue: add sdcardjpa.cpp in lib /sdfilesystem_warning_fixed
38domo 0:48863a0964f5 33 // isue with big fonts: replace /bsp_disco_f746ng/drivers/stm32746ng-discovery/stm32746ng-discovery_lcd.c &.h
38domo 0:48863a0964f5 34
38domo 0:48863a0964f5 35 // need to add CAN and WiFi
38domo 0:48863a0964f5 36
38domo 0:48863a0964f5 37 STM32F746 GroveStreams Stream Feed via Ethernet
38domo 0:48863a0964f5 38
38domo 0:48863a0964f5 39 This GroveStreams example is designed for the STM32F746.
38domo 0:48863a0964f5 40 https://www.grovestreams.com/developers/getting_started_stm32F746.html
38domo 0:48863a0964f5 41
38domo 0:48863a0964f5 42 The STM32 uses DHCP and DNS for a simpler network setup.
38domo 0:48863a0964f5 43
38domo 0:48863a0964f5 44 */
38domo 0:48863a0964f5 45
38domo 0:48863a0964f5 46 #if !FEATURE_LWIP
38domo 0:48863a0964f5 47 #error [NOT_SUPPORTED] LWIP not supported for this target
38domo 0:48863a0964f5 48 #endif
38domo 0:48863a0964f5 49
38domo 0:48863a0964f5 50 #include "mbed.h"
38domo 0:48863a0964f5 51 #include "LcdDiscoF746NgTracer.h"
38domo 0:48863a0964f5 52 #include "GroveStreams.h"
38domo 0:48863a0964f5 53 #include "MbedJSONValue.h"
38domo 0:48863a0964f5 54 #include "stm32746g_discovery_lcd.h"
38domo 0:48863a0964f5 55 #include "stm32746g_discovery_ts.h"
38domo 0:48863a0964f5 56 #include "CANMsg.h"
jeanpierreaulas 3:2de8e4771674 57 //#include "ManageBufferJPA.h"
38domo 0:48863a0964f5 58
38domo 0:48863a0964f5 59 #include "main.h"
38domo 0:48863a0964f5 60
jeanpierreaulas 3:2de8e4771674 61
38domo 0:48863a0964f5 62 //#include "touchScreen.cpp"
38domo 0:48863a0964f5 63 int touchInitJPA1();
38domo 0:48863a0964f5 64 int touchJPA1();
38domo 0:48863a0964f5 65 int touchInitGuiJPA1();
38domo 0:48863a0964f5 66 int sendTouchJPA(int xx);
38domo 0:48863a0964f5 67 time_t lastToucheTime = 0;
38domo 0:48863a0964f5 68 int touchButtonJPA1(int numButton);
38domo 0:48863a0964f5 69
38domo 0:48863a0964f5 70 //#include "GuiJPA.cpp"
38domo 0:48863a0964f5 71 int initDisplayTemp();
38domo 0:48863a0964f5 72 int initDatasGuiJPA();
38domo 0:48863a0964f5 73 int setTemp1(std::string temp1);
38domo 0:48863a0964f5 74 int setTemp2(std::string temp2);
38domo 0:48863a0964f5 75 int sendInitDatasJPA(int xx);
38domo 0:48863a0964f5 76
38domo 0:48863a0964f5 77 //#SDCARD
38domo 0:48863a0964f5 78 int mainSDCardJPA(); //in sdcardjpa.cpp in lib /sdfilesystem_warning_fixedd
38domo 0:48863a0964f5 79
38domo 0:48863a0964f5 80 //GroveStreams Stream IDs. Stream IDs tell GroveStreams which component streams the values will be assigned to.
38domo 0:48863a0964f5 81 //Don't change these unless you edit your GroveStreams component definition and change the stream IDs to match these.
jeanpierreaulas 3:2de8e4771674 82 const char gsStreamId1[] = "voltage";
jeanpierreaulas 3:2de8e4771674 83 const char gsStreamId2[] = "temperature";
jeanpierreaulas 3:2de8e4771674 84 char gsStreamIPdatas[] = "192.168.1.49";
jeanpierreaulas 3:2de8e4771674 85 char ethernet_actif[] = "O";
jeanpierreaulas 3:2de8e4771674 86 char wifi_actif[] = "O";
jeanpierreaulas 3:2de8e4771674 87 char can_actif[] = "O";
jeanpierreaulas 3:2de8e4771674 88 char serial_actif[] = "O";
jeanpierreaulas 3:2de8e4771674 89 char read_sd[] = "";
jeanpierreaulas 3:2de8e4771674 90 uint8_t text2[30];
jeanpierreaulas 3:2de8e4771674 91 uint8_t counter = 0;
jeanpierreaulas 3:2de8e4771674 92 float voltage;
jeanpierreaulas 3:2de8e4771674 93
jeanpierreaulas 3:2de8e4771674 94 Timer timer;
38domo 0:48863a0964f5 95 AnalogIn analogIn(A0);
38domo 0:48863a0964f5 96
38domo 0:48863a0964f5 97 // CAN ------------------------------------------------------------
jeanpierreaulas 3:2de8e4771674 98 CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name
jeanpierreaulas 3:2de8e4771674 99 CANMsg rxMsg;
jeanpierreaulas 3:2de8e4771674 100 CANMsg txMsg;
38domo 0:48863a0964f5 101
38domo 0:48863a0964f5 102 // Other Settings
jeanpierreaulas 3:2de8e4771674 103 int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency.
jeanpierreaulas 3:2de8e4771674 104
jeanpierreaulas 3:2de8e4771674 105 AnalogIn adc_temp(ADC_TEMP);
jeanpierreaulas 3:2de8e4771674 106 AnalogIn adc_vref(ADC_VREF);
jeanpierreaulas 3:2de8e4771674 107 DigitalOut myled(LED1);
38domo 0:48863a0964f5 108
jeanpierreaulas 3:2de8e4771674 109 void initSerial();
jeanpierreaulas 3:2de8e4771674 110 void sendSerialUSB(char * str);
jeanpierreaulas 3:2de8e4771674 111 void receiveSerialUSB();
jeanpierreaulas 4:fbbf5d1785e7 112 void sendSerial2(char * str);
jeanpierreaulas 4:fbbf5d1785e7 113 void receiveSerial2();
jeanpierreaulas 4:fbbf5d1785e7 114 void sendSerial7(char * str);
jeanpierreaulas 4:fbbf5d1785e7 115 void receiveSerial7();
38domo 0:48863a0964f5 116
jeanpierreaulas 4:fbbf5d1785e7 117 //extern volatile char bufferSerialUSB[];
jeanpierreaulas 3:2de8e4771674 118 extern volatile int msgSerialUSB;
jeanpierreaulas 4:fbbf5d1785e7 119 extern volatile int msgSerial2;
jeanpierreaulas 4:fbbf5d1785e7 120 extern volatile int msgSerial7;
jeanpierreaulas 3:2de8e4771674 121
jeanpierreaulas 3:2de8e4771674 122 //extern Serial serialUSB(USBTX, USBRX); // serial PC
jeanpierreaulas 3:2de8e4771674 123 //extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge
jeanpierreaulas 3:2de8e4771674 124 //extern Serial serial7(PF_7, PF_6); // TX, RX for extension
38domo 0:48863a0964f5 125
38domo 0:48863a0964f5 126 #define BOARD1 1 // comment out this line when compiling for board #2
38domo 0:48863a0964f5 127 const unsigned int RX_ID = 0x101;
38domo 0:48863a0964f5 128 const unsigned int TX_ID = 0x100;
jeanpierreaulas 3:2de8e4771674 129
38domo 0:48863a0964f5 130
38domo 0:48863a0964f5 131 // ---------------------------------------------------------------------------------------
38domo 0:48863a0964f5 132 //* @brief Prints CAN message to PC's serial terminal
38domo 0:48863a0964f5 133 void printMsg(CANMessage& msg, int dir)
38domo 0:48863a0964f5 134 { if (dir ==0)
38domo 0:48863a0964f5 135 { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE);
jeanpierreaulas 7:6ec7a4b94d0b 136 printf(" Can message sent : ");
jeanpierreaulas 2:462b5c0d3472 137 printf("ID = 0x%.3X Data=", msg.id);
jeanpierreaulas 2:462b5c0d3472 138 for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]);
jeanpierreaulas 7:6ec7a4b94d0b 139 printf("\n");
38domo 0:48863a0964f5 140 }
38domo 0:48863a0964f5 141 else
jeanpierreaulas 2:462b5c0d3472 142 {
jeanpierreaulas 7:6ec7a4b94d0b 143 printf(" Can message receive : ");
jeanpierreaulas 4:fbbf5d1785e7 144 /*
jeanpierreaulas 2:462b5c0d3472 145 printf(" ID = 0x%.3X\r\n", msg.id);
jeanpierreaulas 2:462b5c0d3472 146 printf(" Type = %d\r\n", msg.type);
jeanpierreaulas 2:462b5c0d3472 147 printf(" Format = %d\r\n", msg.format);
jeanpierreaulas 2:462b5c0d3472 148 printf(" Length = %d\r\n", msg.len);
jeanpierreaulas 7:6ec7a4b94d0b 149 */
jeanpierreaulas 4:fbbf5d1785e7 150 printf("ID = 0x%.3X Data=", msg.id);
jeanpierreaulas 4:fbbf5d1785e7 151 for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]);
jeanpierreaulas 7:6ec7a4b94d0b 152 printf("\n");
38domo 0:48863a0964f5 153 }
38domo 0:48863a0964f5 154 }
38domo 0:48863a0964f5 155
38domo 0:48863a0964f5 156 /** -----------------------------------------------------------------------------------------
38domo 0:48863a0964f5 157 * @brief Handles received CAN messages
38domo 0:48863a0964f5 158 * @note Called on 'CAN message received' interrupt.
38domo 0:48863a0964f5 159 */
jeanpierreaulas 2:462b5c0d3472 160 int CanRcv = 0;
38domo 0:48863a0964f5 161 void onCanReceived(void)
jeanpierreaulas 2:462b5c0d3472 162 {
jeanpierreaulas 2:462b5c0d3472 163 can.read(rxMsg);
jeanpierreaulas 2:462b5c0d3472 164 CanRcv = 1;
38domo 0:48863a0964f5 165 }
jeanpierreaulas 3:2de8e4771674 166
38domo 0:48863a0964f5 167
38domo 0:48863a0964f5 168 // ------------------------------------------------------------------------------------------
38domo 0:48863a0964f5 169 int main()
jeanpierreaulas 3:2de8e4771674 170 {
jeanpierreaulas 3:2de8e4771674 171 initSerial();
jeanpierreaulas 3:2de8e4771674 172
38domo 0:48863a0964f5 173
jeanpierreaulas 2:462b5c0d3472 174 // attach ISR to handle received messages
38domo 0:48863a0964f5 175 timer.start(); // start timer
jeanpierreaulas 3:2de8e4771674 176 sendSerialUSB("CAN_Hello board serialUSB #1\r\n");
jeanpierreaulas 5:ceefd0cfa233 177 sendSerial2("CAN_Hello board serial2 #1\r\n");
jeanpierreaulas 5:ceefd0cfa233 178 sendSerial7("CAN_Hello board serial7 #1\r\n");
jeanpierreaulas 3:2de8e4771674 179
38domo 0:48863a0964f5 180 printf("\nInit SDCard ...\n");
38domo 0:48863a0964f5 181 mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib
38domo 0:48863a0964f5 182 // reaf following datas
38domo 0:48863a0964f5 183 // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters
38domo 0:48863a0964f5 184 // store local variables from sd
38domo 0:48863a0964f5 185 //extern char gsStreamIPdatas[];
38domo 0:48863a0964f5 186 //extern char ethernet_actif[] ;
38domo 0:48863a0964f5 187 //extern char wifi_actif[];
38domo 0:48863a0964f5 188 //extern char can_actif[];
38domo 0:48863a0964f5 189 //extern char serial_actif[];
38domo 0:48863a0964f5 190 printf("\nFin init SDCard ...\n");
38domo 0:48863a0964f5 191 BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD
38domo 0:48863a0964f5 192 uint8_t text[300];
38domo 0:48863a0964f5 193 printf("Start Prog\n");
38domo 0:48863a0964f5 194 std::string temp1;
38domo 0:48863a0964f5 195 std::string temp2;
38domo 0:48863a0964f5 196
38domo 0:48863a0964f5 197 //lastSuccessfulUploadTime is used for upload frequency.
38domo 0:48863a0964f5 198 time_t lastSuccessfulUploadTime = 0;
38domo 0:48863a0964f5 199 printf("\n Init touchJPA1 ...\n");
38domo 0:48863a0964f5 200 int yy;
38domo 0:48863a0964f5 201 printf("\n Init initDisplayTemp ...\n");
38domo 0:48863a0964f5 202 yy = initDisplayTemp(); // from guijpa.cpp - Init display
38domo 0:48863a0964f5 203 printf("\ninit touchInitJPA1 ...\n");
38domo 0:48863a0964f5 204 yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen
38domo 0:48863a0964f5 205 yy = touchInitGuiJPA1(); // from touchscreen.cpp
38domo 0:48863a0964f5 206 printf("\ninit initDatasGuiJPA ...\n");
38domo 0:48863a0964f5 207 yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons
38domo 0:48863a0964f5 208 ////lcd.printf("Starting...");
38domo 0:48863a0964f5 209 printf("Starting...\n");
38domo 0:48863a0964f5 210 lastToucheTime = time(NULL);
38domo 0:48863a0964f5 211 char data[5];
jeanpierreaulas 2:462b5c0d3472 212
jeanpierreaulas 2:462b5c0d3472 213 // config can --------------------------------------
jeanpierreaulas 2:462b5c0d3472 214 can.frequency(125000); // set CAN bit rate to 125 kbps
jeanpierreaulas 2:462b5c0d3472 215 //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID
jeanpierreaulas 3:2de8e4771674 216 can.attach(onCanReceived, CAN::RxIrq);
jeanpierreaulas 2:462b5c0d3472 217
jeanpierreaulas 5:ceefd0cfa233 218 BSP_LCD_DisplayOff();
jeanpierreaulas 5:ceefd0cfa233 219 BSP_LCD_DisplayOn();
jeanpierreaulas 3:2de8e4771674 220 // main loop ---------------------------------------------------
38domo 0:48863a0964f5 221 while (true) {
jeanpierreaulas 2:462b5c0d3472 222
jeanpierreaulas 2:462b5c0d3472 223 if (CanRcv > 0)
jeanpierreaulas 2:462b5c0d3472 224 {
jeanpierreaulas 2:462b5c0d3472 225 CanRcv = 0;
jeanpierreaulas 2:462b5c0d3472 226 printMsg(rxMsg,1);
jeanpierreaulas 2:462b5c0d3472 227 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE);
jeanpierreaulas 2:462b5c0d3472 228 if (rxMsg.id == RX_ID) {
jeanpierreaulas 2:462b5c0d3472 229 rxMsg >> counter;
jeanpierreaulas 2:462b5c0d3472 230 rxMsg >> voltage;
jeanpierreaulas 3:2de8e4771674 231 //serialUSB.printf(" counter = %d\r\n", counter);
jeanpierreaulas 3:2de8e4771674 232 //serialUSB.printf(" voltage = %e V\r\n", voltage);
jeanpierreaulas 2:462b5c0d3472 233 }
jeanpierreaulas 2:462b5c0d3472 234 }
jeanpierreaulas 3:2de8e4771674 235
jeanpierreaulas 3:2de8e4771674 236 if (msgSerialUSB > 0) {receiveSerialUSB();}
jeanpierreaulas 4:fbbf5d1785e7 237 if (msgSerial2 > 0) {receiveSerial2();}
jeanpierreaulas 4:fbbf5d1785e7 238 if (msgSerial7 > 0) {receiveSerial7();}
jeanpierreaulas 3:2de8e4771674 239
38domo 0:48863a0964f5 240 // timer send can
jeanpierreaulas 3:2de8e4771674 241 if(timer.read_ms() >= 10000) // check for timeout
jeanpierreaulas 5:ceefd0cfa233 242 {
jeanpierreaulas 5:ceefd0cfa233 243
jeanpierreaulas 5:ceefd0cfa233 244 timer.stop(); // stop the timer
38domo 0:48863a0964f5 245 timer.reset(); // reset the timer
jeanpierreaulas 2:462b5c0d3472 246 counter = (counter+1) & 1; // increment the counter
jeanpierreaulas 2:462b5c0d3472 247 voltage = 0;////(analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input
38domo 0:48863a0964f5 248 txMsg.clear(); // clear the Tx message storage
jeanpierreaulas 2:462b5c0d3472 249 txMsg.id = 0x100130CA;//TX_ID; // set the message ID
38domo 0:48863a0964f5 250 txMsg.format = CANExtended ; //extended
jeanpierreaulas 2:462b5c0d3472 251 txMsg.len=2;
jeanpierreaulas 2:462b5c0d3472 252 txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!)
38domo 0:48863a0964f5 253
38domo 0:48863a0964f5 254 if(can.write(txMsg)) // transmit message
38domo 0:48863a0964f5 255 { //if(can->write(txMsg)) { // transmit the CAN message
38domo 0:48863a0964f5 256 printMsg(txMsg,0);
38domo 0:48863a0964f5 257 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
38domo 0:48863a0964f5 258 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
38domo 0:48863a0964f5 259 }
38domo 0:48863a0964f5 260 else
jeanpierreaulas 3:2de8e4771674 261 { //serialUSB.printf("Transmission error\r\n");
38domo 0:48863a0964f5 262 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
38domo 0:48863a0964f5 263 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
38domo 0:48863a0964f5 264 }
jeanpierreaulas 2:462b5c0d3472 265 timer.start(); // insert transmission lag
38domo 0:48863a0964f5 266 } // end if timer
38domo 0:48863a0964f5 267 //touch screen
38domo 0:48863a0964f5 268 int xx = touchJPA1(); //
38domo 0:48863a0964f5 269 if (xx > 0)
jeanpierreaulas 3:2de8e4771674 270 {
jeanpierreaulas 3:2de8e4771674 271 if (xx == 4)
38domo 0:48863a0964f5 272 { // send trame to can
jeanpierreaulas 3:2de8e4771674 273 txMsg.id = 0x100130CB;//TX_ID; // set the message ID
jeanpierreaulas 3:2de8e4771674 274 txMsg.format = CANExtended ; //extended
jeanpierreaulas 3:2de8e4771674 275 txMsg.len=2;
jeanpierreaulas 3:2de8e4771674 276 txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!)
jeanpierreaulas 3:2de8e4771674 277
38domo 0:48863a0964f5 278 if(can.write(txMsg)) // transmit message
jeanpierreaulas 3:2de8e4771674 279 {
38domo 0:48863a0964f5 280 printMsg(txMsg,0);
38domo 0:48863a0964f5 281 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
38domo 0:48863a0964f5 282 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
jeanpierreaulas 3:2de8e4771674 283 }
38domo 0:48863a0964f5 284 else
jeanpierreaulas 3:2de8e4771674 285 {
38domo 0:48863a0964f5 286 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
38domo 0:48863a0964f5 287 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
38domo 0:48863a0964f5 288 }
38domo 0:48863a0964f5 289 }
38domo 0:48863a0964f5 290 xx = sendTouchJPA(xx);
38domo 0:48863a0964f5 291
38domo 0:48863a0964f5 292 lastToucheTime = time(NULL);
38domo 0:48863a0964f5 293
38domo 0:48863a0964f5 294 }
38domo 0:48863a0964f5 295 else
38domo 0:48863a0964f5 296 { lastToucheTime = 0;
38domo 0:48863a0964f5 297 } // send mqtt
38domo 0:48863a0964f5 298 // Update sensor data to GroveStreams
jeanpierreaulas 3:2de8e4771674 299 time_t seconds = time(NULL);
38domo 0:48863a0964f5 300 if(seconds - lastSuccessfulUploadTime > updateFrequency) {
38domo 0:48863a0964f5 301 ////lcd.clear();
38domo 0:48863a0964f5 302 ////lcd.printf("Getting Samples...");
38domo 0:48863a0964f5 303 printf("Getting Samples...\n");
38domo 0:48863a0964f5 304 //Assemble the samples into URL parameters which are seperated with the "&" character
38domo 0:48863a0964f5 305 // Example: &s1=6.2&s2=78.231
jeanpierreaulas 2:462b5c0d3472 306 int temperature = 0; //adc_temp.read() * 100.0f;
jeanpierreaulas 2:462b5c0d3472 307 int voltage = 0; //adc_vref.read() * 100.0f;
38domo 0:48863a0964f5 308 char samples[64] = {0};
38domo 0:48863a0964f5 309 sprintf(samples, "&%s=%d&%s=%d", gsStreamId1, voltage, gsStreamId2, temperature);
38domo 0:48863a0964f5 310 //Append on command requests (request stream values)
38domo 0:48863a0964f5 311 //This will indicate to GroveStreams to return the last value
38domo 0:48863a0964f5 312 // of each request stream during the sample upload
38domo 0:48863a0964f5 313 strcat(samples, "&rsid=freq&rsid=led");
38domo 0:48863a0964f5 314 char resultBuffer[700]= {0};
38domo 0:48863a0964f5 315 //Sending Samples (and returning current command stream values)
38domo 0:48863a0964f5 316 time_t connectAttemptTime = time(NULL);
38domo 0:48863a0964f5 317 int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); //receive mqtt
38domo 0:48863a0964f5 318
38domo 0:48863a0964f5 319 if (sendResult == 0) {
38domo 0:48863a0964f5 320 ////lcd.printf("Send Successful");
38domo 0:48863a0964f5 321 printf("Send Successful\n");
38domo 0:48863a0964f5 322 lastSuccessfulUploadTime = connectAttemptTime;
38domo 0:48863a0964f5 323 //Handle command streams
38domo 0:48863a0964f5 324 if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') {
38domo 0:48863a0964f5 325 MbedJSONValue mbedJson;
38domo 0:48863a0964f5 326 parse(mbedJson, resultBuffer);
38domo 0:48863a0964f5 327 sprintf((char*)text, "HTTP string : %s\n", resultBuffer);
38domo 0:48863a0964f5 328 //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 329 if (mbedJson.hasMember("Temp1")) {
38domo 0:48863a0964f5 330 int pp=setTemp1(mbedJson["Temp1"].get<std::string>());
38domo 0:48863a0964f5 331 }
38domo 0:48863a0964f5 332 if (mbedJson.hasMember("Temp2")) {
38domo 0:48863a0964f5 333 int tt=setTemp2(mbedJson["Temp2"].get<std::string>());
38domo 0:48863a0964f5 334 }
38domo 0:48863a0964f5 335 if (mbedJson.hasMember("led")) {
38domo 0:48863a0964f5 336 //Change LED
38domo 0:48863a0964f5 337 myled = mbedJson["led"].get<bool>() ? 1 : 0;
38domo 0:48863a0964f5 338 ////lcd.printf("LED: %s", mbedJson["led"].get<bool>() ? "On" : "Off");
38domo 0:48863a0964f5 339 printf("LED: %s\n", mbedJson["led"].get<bool>() ? "On" : "Off");
38domo 0:48863a0964f5 340 }
38domo 0:48863a0964f5 341 }
38domo 0:48863a0964f5 342 }
38domo 0:48863a0964f5 343 }
38domo 0:48863a0964f5 344
38domo 0:48863a0964f5 345 }
38domo 0:48863a0964f5 346 }
38domo 0:48863a0964f5 347
38domo 0:48863a0964f5 348