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:
Wed Sep 02 17:07:55 2020 +0000
Branch:
jpa
Revision:
5:ceefd0cfa233
Parent:
4:fbbf5d1785e7
Child:
7:6ec7a4b94d0b
for test serial send

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