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:
38domo
Date:
Wed Jan 13 19:52:35 2021 +0000
Branch:
jpa
Revision:
17:f3c5ec9ca00f
Parent:
10:41aff2b7acc6
version 12/01 without ethernet, only tasmota wifi and can

Who changed what in which revision?

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