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:
Tue Sep 08 15:00:05 2020 +0000
Branch:
jpa
Revision:
8:275ae4382788
Parent:
7:6ec7a4b94d0b
Child:
9:332bd237b98f
add buffer trame user

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 8:275ae4382788 119 extern char stringSerialUSB[]; // trame from serialUSB
jeanpierreaulas 8:275ae4382788 120 extern int stringSerialUSBok; // si ==1 alors trame dispo (fin de trame == LF ou 10
jeanpierreaulas 8:275ae4382788 121
jeanpierreaulas 4:fbbf5d1785e7 122 extern volatile int msgSerial2;
jeanpierreaulas 8:275ae4382788 123 extern char stringSerial2[]; // trame from serialUSB
jeanpierreaulas 8:275ae4382788 124 extern int stringSerial2ok; // si ==1 alors trame dispo (fin de trame == LF ou 10
jeanpierreaulas 8:275ae4382788 125
jeanpierreaulas 4:fbbf5d1785e7 126 extern volatile int msgSerial7;
jeanpierreaulas 8:275ae4382788 127 extern char stringSerial7[]; // trame from serialUSB
jeanpierreaulas 8:275ae4382788 128 extern int stringSerial7ok; // si ==1 alors trame dispo (fin de trame == LF ou 10
jeanpierreaulas 3:2de8e4771674 129
jeanpierreaulas 3:2de8e4771674 130 //extern Serial serialUSB(USBTX, USBRX); // serial PC
jeanpierreaulas 3:2de8e4771674 131 //extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge
jeanpierreaulas 3:2de8e4771674 132 //extern Serial serial7(PF_7, PF_6); // TX, RX for extension
38domo 0:48863a0964f5 133
38domo 0:48863a0964f5 134 #define BOARD1 1 // comment out this line when compiling for board #2
38domo 0:48863a0964f5 135 const unsigned int RX_ID = 0x101;
38domo 0:48863a0964f5 136 const unsigned int TX_ID = 0x100;
jeanpierreaulas 3:2de8e4771674 137
38domo 0:48863a0964f5 138
38domo 0:48863a0964f5 139 // ---------------------------------------------------------------------------------------
38domo 0:48863a0964f5 140 //* @brief Prints CAN message to PC's serial terminal
38domo 0:48863a0964f5 141 void printMsg(CANMessage& msg, int dir)
38domo 0:48863a0964f5 142 { if (dir ==0)
38domo 0:48863a0964f5 143 { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE);
jeanpierreaulas 7:6ec7a4b94d0b 144 printf(" Can message sent : ");
jeanpierreaulas 2:462b5c0d3472 145 printf("ID = 0x%.3X Data=", msg.id);
jeanpierreaulas 2:462b5c0d3472 146 for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]);
jeanpierreaulas 7:6ec7a4b94d0b 147 printf("\n");
38domo 0:48863a0964f5 148 }
38domo 0:48863a0964f5 149 else
jeanpierreaulas 2:462b5c0d3472 150 {
jeanpierreaulas 7:6ec7a4b94d0b 151 printf(" Can message receive : ");
jeanpierreaulas 4:fbbf5d1785e7 152 /*
jeanpierreaulas 2:462b5c0d3472 153 printf(" ID = 0x%.3X\r\n", msg.id);
jeanpierreaulas 2:462b5c0d3472 154 printf(" Type = %d\r\n", msg.type);
jeanpierreaulas 2:462b5c0d3472 155 printf(" Format = %d\r\n", msg.format);
jeanpierreaulas 2:462b5c0d3472 156 printf(" Length = %d\r\n", msg.len);
jeanpierreaulas 7:6ec7a4b94d0b 157 */
jeanpierreaulas 4:fbbf5d1785e7 158 printf("ID = 0x%.3X Data=", msg.id);
jeanpierreaulas 4:fbbf5d1785e7 159 for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]);
jeanpierreaulas 7:6ec7a4b94d0b 160 printf("\n");
38domo 0:48863a0964f5 161 }
38domo 0:48863a0964f5 162 }
38domo 0:48863a0964f5 163
38domo 0:48863a0964f5 164 /** -----------------------------------------------------------------------------------------
38domo 0:48863a0964f5 165 * @brief Handles received CAN messages
38domo 0:48863a0964f5 166 * @note Called on 'CAN message received' interrupt.
38domo 0:48863a0964f5 167 */
jeanpierreaulas 2:462b5c0d3472 168 int CanRcv = 0;
38domo 0:48863a0964f5 169 void onCanReceived(void)
jeanpierreaulas 2:462b5c0d3472 170 {
jeanpierreaulas 2:462b5c0d3472 171 can.read(rxMsg);
jeanpierreaulas 2:462b5c0d3472 172 CanRcv = 1;
38domo 0:48863a0964f5 173 }
jeanpierreaulas 3:2de8e4771674 174
38domo 0:48863a0964f5 175
38domo 0:48863a0964f5 176 // ------------------------------------------------------------------------------------------
38domo 0:48863a0964f5 177 int main()
jeanpierreaulas 3:2de8e4771674 178 {
jeanpierreaulas 3:2de8e4771674 179 initSerial();
jeanpierreaulas 3:2de8e4771674 180
38domo 0:48863a0964f5 181
jeanpierreaulas 2:462b5c0d3472 182 // attach ISR to handle received messages
38domo 0:48863a0964f5 183 timer.start(); // start timer
jeanpierreaulas 3:2de8e4771674 184 sendSerialUSB("CAN_Hello board serialUSB #1\r\n");
jeanpierreaulas 5:ceefd0cfa233 185 sendSerial2("CAN_Hello board serial2 #1\r\n");
jeanpierreaulas 5:ceefd0cfa233 186 sendSerial7("CAN_Hello board serial7 #1\r\n");
jeanpierreaulas 3:2de8e4771674 187
38domo 0:48863a0964f5 188 printf("\nInit SDCard ...\n");
38domo 0:48863a0964f5 189 mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib
38domo 0:48863a0964f5 190 // reaf following datas
38domo 0:48863a0964f5 191 // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters
38domo 0:48863a0964f5 192 // store local variables from sd
38domo 0:48863a0964f5 193 //extern char gsStreamIPdatas[];
38domo 0:48863a0964f5 194 //extern char ethernet_actif[] ;
38domo 0:48863a0964f5 195 //extern char wifi_actif[];
38domo 0:48863a0964f5 196 //extern char can_actif[];
38domo 0:48863a0964f5 197 //extern char serial_actif[];
38domo 0:48863a0964f5 198 printf("\nFin init SDCard ...\n");
38domo 0:48863a0964f5 199 BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD
38domo 0:48863a0964f5 200 uint8_t text[300];
38domo 0:48863a0964f5 201 printf("Start Prog\n");
38domo 0:48863a0964f5 202 std::string temp1;
38domo 0:48863a0964f5 203 std::string temp2;
38domo 0:48863a0964f5 204
38domo 0:48863a0964f5 205 //lastSuccessfulUploadTime is used for upload frequency.
38domo 0:48863a0964f5 206 time_t lastSuccessfulUploadTime = 0;
38domo 0:48863a0964f5 207 printf("\n Init touchJPA1 ...\n");
38domo 0:48863a0964f5 208 int yy;
38domo 0:48863a0964f5 209 printf("\n Init initDisplayTemp ...\n");
38domo 0:48863a0964f5 210 yy = initDisplayTemp(); // from guijpa.cpp - Init display
38domo 0:48863a0964f5 211 printf("\ninit touchInitJPA1 ...\n");
38domo 0:48863a0964f5 212 yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen
38domo 0:48863a0964f5 213 yy = touchInitGuiJPA1(); // from touchscreen.cpp
38domo 0:48863a0964f5 214 printf("\ninit initDatasGuiJPA ...\n");
38domo 0:48863a0964f5 215 yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons
38domo 0:48863a0964f5 216 ////lcd.printf("Starting...");
38domo 0:48863a0964f5 217 printf("Starting...\n");
38domo 0:48863a0964f5 218 lastToucheTime = time(NULL);
38domo 0:48863a0964f5 219 char data[5];
jeanpierreaulas 2:462b5c0d3472 220
jeanpierreaulas 2:462b5c0d3472 221 // config can --------------------------------------
jeanpierreaulas 2:462b5c0d3472 222 can.frequency(125000); // set CAN bit rate to 125 kbps
jeanpierreaulas 2:462b5c0d3472 223 //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID
jeanpierreaulas 3:2de8e4771674 224 can.attach(onCanReceived, CAN::RxIrq);
jeanpierreaulas 2:462b5c0d3472 225
jeanpierreaulas 5:ceefd0cfa233 226 BSP_LCD_DisplayOff();
jeanpierreaulas 5:ceefd0cfa233 227 BSP_LCD_DisplayOn();
jeanpierreaulas 3:2de8e4771674 228 // main loop ---------------------------------------------------
38domo 0:48863a0964f5 229 while (true) {
jeanpierreaulas 2:462b5c0d3472 230
jeanpierreaulas 2:462b5c0d3472 231 if (CanRcv > 0)
jeanpierreaulas 2:462b5c0d3472 232 {
jeanpierreaulas 2:462b5c0d3472 233 CanRcv = 0;
jeanpierreaulas 2:462b5c0d3472 234 printMsg(rxMsg,1);
jeanpierreaulas 2:462b5c0d3472 235 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE);
jeanpierreaulas 2:462b5c0d3472 236 if (rxMsg.id == RX_ID) {
jeanpierreaulas 2:462b5c0d3472 237 rxMsg >> counter;
jeanpierreaulas 2:462b5c0d3472 238 rxMsg >> voltage;
jeanpierreaulas 3:2de8e4771674 239 //serialUSB.printf(" counter = %d\r\n", counter);
jeanpierreaulas 3:2de8e4771674 240 //serialUSB.printf(" voltage = %e V\r\n", voltage);
jeanpierreaulas 2:462b5c0d3472 241 }
jeanpierreaulas 2:462b5c0d3472 242 }
jeanpierreaulas 3:2de8e4771674 243
jeanpierreaulas 3:2de8e4771674 244 if (msgSerialUSB > 0) {receiveSerialUSB();}
jeanpierreaulas 8:275ae4382788 245 if (stringSerialUSBok == 1) {stringSerialUSBok=0;printf("Trame SerialUSB : %s",stringSerialUSB);}
jeanpierreaulas 8:275ae4382788 246
jeanpierreaulas 4:fbbf5d1785e7 247 if (msgSerial2 > 0) {receiveSerial2();}
jeanpierreaulas 8:275ae4382788 248 if (stringSerial2ok == 1) {stringSerial2ok=0;printf("Trame Serial2 : %s",stringSerial2);}
jeanpierreaulas 8:275ae4382788 249
jeanpierreaulas 4:fbbf5d1785e7 250 if (msgSerial7 > 0) {receiveSerial7();}
jeanpierreaulas 8:275ae4382788 251 if (stringSerial7ok == 1) {stringSerial7ok=0;printf("Trame Serial7 : %s",stringSerial7);}
jeanpierreaulas 3:2de8e4771674 252
38domo 0:48863a0964f5 253 // timer send can
jeanpierreaulas 3:2de8e4771674 254 if(timer.read_ms() >= 10000) // check for timeout
jeanpierreaulas 5:ceefd0cfa233 255 {
jeanpierreaulas 5:ceefd0cfa233 256
jeanpierreaulas 5:ceefd0cfa233 257 timer.stop(); // stop the timer
38domo 0:48863a0964f5 258 timer.reset(); // reset the timer
jeanpierreaulas 2:462b5c0d3472 259 counter = (counter+1) & 1; // increment the counter
jeanpierreaulas 2:462b5c0d3472 260 voltage = 0;////(analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input
38domo 0:48863a0964f5 261 txMsg.clear(); // clear the Tx message storage
jeanpierreaulas 2:462b5c0d3472 262 txMsg.id = 0x100130CA;//TX_ID; // set the message ID
38domo 0:48863a0964f5 263 txMsg.format = CANExtended ; //extended
jeanpierreaulas 2:462b5c0d3472 264 txMsg.len=2;
jeanpierreaulas 2:462b5c0d3472 265 txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!)
38domo 0:48863a0964f5 266
38domo 0:48863a0964f5 267 if(can.write(txMsg)) // transmit message
38domo 0:48863a0964f5 268 { //if(can->write(txMsg)) { // transmit the CAN message
38domo 0:48863a0964f5 269 printMsg(txMsg,0);
38domo 0:48863a0964f5 270 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
38domo 0:48863a0964f5 271 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
38domo 0:48863a0964f5 272 }
38domo 0:48863a0964f5 273 else
jeanpierreaulas 3:2de8e4771674 274 { //serialUSB.printf("Transmission error\r\n");
38domo 0:48863a0964f5 275 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
38domo 0:48863a0964f5 276 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
38domo 0:48863a0964f5 277 }
jeanpierreaulas 2:462b5c0d3472 278 timer.start(); // insert transmission lag
38domo 0:48863a0964f5 279 } // end if timer
38domo 0:48863a0964f5 280 //touch screen
38domo 0:48863a0964f5 281 int xx = touchJPA1(); //
38domo 0:48863a0964f5 282 if (xx > 0)
jeanpierreaulas 3:2de8e4771674 283 {
jeanpierreaulas 3:2de8e4771674 284 if (xx == 4)
38domo 0:48863a0964f5 285 { // send trame to can
jeanpierreaulas 3:2de8e4771674 286 txMsg.id = 0x100130CB;//TX_ID; // set the message ID
jeanpierreaulas 3:2de8e4771674 287 txMsg.format = CANExtended ; //extended
jeanpierreaulas 3:2de8e4771674 288 txMsg.len=2;
jeanpierreaulas 3:2de8e4771674 289 txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!)
jeanpierreaulas 3:2de8e4771674 290
38domo 0:48863a0964f5 291 if(can.write(txMsg)) // transmit message
jeanpierreaulas 3:2de8e4771674 292 {
38domo 0:48863a0964f5 293 printMsg(txMsg,0);
38domo 0:48863a0964f5 294 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
38domo 0:48863a0964f5 295 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
jeanpierreaulas 3:2de8e4771674 296 }
38domo 0:48863a0964f5 297 else
jeanpierreaulas 3:2de8e4771674 298 {
38domo 0:48863a0964f5 299 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
38domo 0:48863a0964f5 300 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
38domo 0:48863a0964f5 301 }
38domo 0:48863a0964f5 302 }
38domo 0:48863a0964f5 303 xx = sendTouchJPA(xx);
38domo 0:48863a0964f5 304
38domo 0:48863a0964f5 305 lastToucheTime = time(NULL);
38domo 0:48863a0964f5 306
38domo 0:48863a0964f5 307 }
38domo 0:48863a0964f5 308 else
38domo 0:48863a0964f5 309 { lastToucheTime = 0;
38domo 0:48863a0964f5 310 } // send mqtt
38domo 0:48863a0964f5 311 // Update sensor data to GroveStreams
jeanpierreaulas 3:2de8e4771674 312 time_t seconds = time(NULL);
38domo 0:48863a0964f5 313 if(seconds - lastSuccessfulUploadTime > updateFrequency) {
38domo 0:48863a0964f5 314 ////lcd.clear();
38domo 0:48863a0964f5 315 ////lcd.printf("Getting Samples...");
38domo 0:48863a0964f5 316 printf("Getting Samples...\n");
38domo 0:48863a0964f5 317 //Assemble the samples into URL parameters which are seperated with the "&" character
38domo 0:48863a0964f5 318 // Example: &s1=6.2&s2=78.231
jeanpierreaulas 2:462b5c0d3472 319 int temperature = 0; //adc_temp.read() * 100.0f;
jeanpierreaulas 2:462b5c0d3472 320 int voltage = 0; //adc_vref.read() * 100.0f;
38domo 0:48863a0964f5 321 char samples[64] = {0};
38domo 0:48863a0964f5 322 sprintf(samples, "&%s=%d&%s=%d", gsStreamId1, voltage, gsStreamId2, temperature);
38domo 0:48863a0964f5 323 //Append on command requests (request stream values)
38domo 0:48863a0964f5 324 //This will indicate to GroveStreams to return the last value
38domo 0:48863a0964f5 325 // of each request stream during the sample upload
38domo 0:48863a0964f5 326 strcat(samples, "&rsid=freq&rsid=led");
38domo 0:48863a0964f5 327 char resultBuffer[700]= {0};
38domo 0:48863a0964f5 328 //Sending Samples (and returning current command stream values)
38domo 0:48863a0964f5 329 time_t connectAttemptTime = time(NULL);
38domo 0:48863a0964f5 330 int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); //receive mqtt
38domo 0:48863a0964f5 331
38domo 0:48863a0964f5 332 if (sendResult == 0) {
38domo 0:48863a0964f5 333 ////lcd.printf("Send Successful");
38domo 0:48863a0964f5 334 printf("Send Successful\n");
38domo 0:48863a0964f5 335 lastSuccessfulUploadTime = connectAttemptTime;
38domo 0:48863a0964f5 336 //Handle command streams
38domo 0:48863a0964f5 337 if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') {
38domo 0:48863a0964f5 338 MbedJSONValue mbedJson;
38domo 0:48863a0964f5 339 parse(mbedJson, resultBuffer);
38domo 0:48863a0964f5 340 sprintf((char*)text, "HTTP string : %s\n", resultBuffer);
38domo 0:48863a0964f5 341 //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 342 if (mbedJson.hasMember("Temp1")) {
38domo 0:48863a0964f5 343 int pp=setTemp1(mbedJson["Temp1"].get<std::string>());
38domo 0:48863a0964f5 344 }
38domo 0:48863a0964f5 345 if (mbedJson.hasMember("Temp2")) {
38domo 0:48863a0964f5 346 int tt=setTemp2(mbedJson["Temp2"].get<std::string>());
38domo 0:48863a0964f5 347 }
38domo 0:48863a0964f5 348 if (mbedJson.hasMember("led")) {
38domo 0:48863a0964f5 349 //Change LED
38domo 0:48863a0964f5 350 myled = mbedJson["led"].get<bool>() ? 1 : 0;
38domo 0:48863a0964f5 351 ////lcd.printf("LED: %s", mbedJson["led"].get<bool>() ? "On" : "Off");
38domo 0:48863a0964f5 352 printf("LED: %s\n", mbedJson["led"].get<bool>() ? "On" : "Off");
38domo 0:48863a0964f5 353 }
38domo 0:48863a0964f5 354 }
38domo 0:48863a0964f5 355 }
38domo 0:48863a0964f5 356 }
38domo 0:48863a0964f5 357
38domo 0:48863a0964f5 358 }
38domo 0:48863a0964f5 359 }
38domo 0:48863a0964f5 360
38domo 0:48863a0964f5 361