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 12:54:45 2020 +0000
Branch:
jpa
Revision:
3:2de8e4771674
Parent:
2:462b5c0d3472
Child:
4:fbbf5d1785e7
Ethernet ok, Display OK, CAN Ok, SerialUSB OK

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