grove stream updated gerard 31/08

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

Committer:
38domo
Date:
Mon Aug 31 19:19:48 2020 +0000
Revision:
0:48863a0964f5
grove stream upated 31/08

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"
38domo 0:48863a0964f5 57
38domo 0:48863a0964f5 58 #include "main.h"
38domo 0:48863a0964f5 59
38domo 0:48863a0964f5 60 //#include "touchScreen.cpp"
38domo 0:48863a0964f5 61 int touchInitJPA1();
38domo 0:48863a0964f5 62 int touchJPA1();
38domo 0:48863a0964f5 63 int touchInitGuiJPA1();
38domo 0:48863a0964f5 64 int sendTouchJPA(int xx);
38domo 0:48863a0964f5 65 time_t lastToucheTime = 0;
38domo 0:48863a0964f5 66 int touchButtonJPA1(int numButton);
38domo 0:48863a0964f5 67
38domo 0:48863a0964f5 68 //#include "GuiJPA.cpp"
38domo 0:48863a0964f5 69 int initDisplayTemp();
38domo 0:48863a0964f5 70 int initDatasGuiJPA();
38domo 0:48863a0964f5 71 int setTemp1(std::string temp1);
38domo 0:48863a0964f5 72 int setTemp2(std::string temp2);
38domo 0:48863a0964f5 73 int sendInitDatasJPA(int xx);
38domo 0:48863a0964f5 74
38domo 0:48863a0964f5 75 //#SDCARD
38domo 0:48863a0964f5 76 int mainSDCardJPA(); //in sdcardjpa.cpp in lib /sdfilesystem_warning_fixedd
38domo 0:48863a0964f5 77
38domo 0:48863a0964f5 78 //GroveStreams Stream IDs. Stream IDs tell GroveStreams which component streams the values will be assigned to.
38domo 0:48863a0964f5 79 //Don't change these unless you edit your GroveStreams component definition and change the stream IDs to match these.
38domo 0:48863a0964f5 80 const char gsStreamId1[] = "voltage";
38domo 0:48863a0964f5 81 const char gsStreamId2[] = "temperature";
38domo 0:48863a0964f5 82 char gsStreamIPdatas[] = "192.168.1.49";
38domo 0:48863a0964f5 83 char ethernet_actif[] = "O";
38domo 0:48863a0964f5 84 char wifi_actif[] = "O";
38domo 0:48863a0964f5 85 char can_actif[] = "O";
38domo 0:48863a0964f5 86 char serial_actif[] = "O";
38domo 0:48863a0964f5 87 char read_sd[] = "";
38domo 0:48863a0964f5 88 uint8_t text2[30];
38domo 0:48863a0964f5 89 uint8_t counter = 0;
38domo 0:48863a0964f5 90 float voltage;
38domo 0:48863a0964f5 91 const int kMaxBufferSize = 100;
38domo 0:48863a0964f5 92 char buffer[kMaxBufferSize];
38domo 0:48863a0964f5 93 int len = 0;
38domo 0:48863a0964f5 94 int i = 0;
38domo 0:48863a0964f5 95 int idx_ser =0;
38domo 0:48863a0964f5 96 int recv_ser = 0;
38domo 0:48863a0964f5 97 Timer timer;
38domo 0:48863a0964f5 98 AnalogIn analogIn(A0);
38domo 0:48863a0964f5 99
38domo 0:48863a0964f5 100 // CAN ------------------------------------------------------------
38domo 0:48863a0964f5 101 CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name
38domo 0:48863a0964f5 102 CANMsg rxMsg;
38domo 0:48863a0964f5 103 CANMsg txMsg;
38domo 0:48863a0964f5 104
38domo 0:48863a0964f5 105 // Other Settings
38domo 0:48863a0964f5 106 int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency.
38domo 0:48863a0964f5 107
38domo 0:48863a0964f5 108 AnalogIn adc_temp(ADC_TEMP);
38domo 0:48863a0964f5 109 AnalogIn adc_vref(ADC_VREF);
38domo 0:48863a0964f5 110 DigitalOut myled(LED1);
38domo 0:48863a0964f5 111
38domo 0:48863a0964f5 112 // serial port sur connecteur arduino (D0,D1)--------------------
38domo 0:48863a0964f5 113 Serial pc(USBTX, USBRX); // serial PC
38domo 0:48863a0964f5 114 Serial serial2(PC_6, PC_7); // TX, RX for udp bridge
38domo 0:48863a0964f5 115 Serial serial7(PF_7, PF_6); // TX, RX for extension
38domo 0:48863a0964f5 116
38domo 0:48863a0964f5 117 #define BOARD1 1 // comment out this line when compiling for board #2
38domo 0:48863a0964f5 118 #if defined(BOARD1)
38domo 0:48863a0964f5 119 const unsigned int RX_ID = 0x100;
38domo 0:48863a0964f5 120 const unsigned int TX_ID = 0x101;
38domo 0:48863a0964f5 121 #else
38domo 0:48863a0964f5 122 const unsigned int RX_ID = 0x101;
38domo 0:48863a0964f5 123 const unsigned int TX_ID = 0x100;
38domo 0:48863a0964f5 124 #endif
38domo 0:48863a0964f5 125
38domo 0:48863a0964f5 126 // ---------------------------------------------------------------------------------------
38domo 0:48863a0964f5 127 //* @brief Prints CAN message to PC's serial terminal
38domo 0:48863a0964f5 128 void printMsg(CANMessage& msg, int dir)
38domo 0:48863a0964f5 129 { if (dir ==0)
38domo 0:48863a0964f5 130 { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE);
38domo 0:48863a0964f5 131 serial7.printf(" Can message sent ok\n");
38domo 0:48863a0964f5 132 serial7.printf("ID = 0x%.3x Data=", msg.id);
38domo 0:48863a0964f5 133 for(int i = 0; i < msg.len; i++)
38domo 0:48863a0964f5 134 serial7.printf(" 0x%.2X", msg.data[i]);
38domo 0:48863a0964f5 135 serial7.printf("\r\n");
38domo 0:48863a0964f5 136 }
38domo 0:48863a0964f5 137 else
38domo 0:48863a0964f5 138 { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message received", LEFT_MODE);
38domo 0:48863a0964f5 139 }
38domo 0:48863a0964f5 140 pc.printf(" ID = 0x%.3x\r\n", msg.id);
38domo 0:48863a0964f5 141 pc.printf(" Type = %d\r\n", msg.type);
38domo 0:48863a0964f5 142 pc.printf(" Format = %d\r\n", msg.format);
38domo 0:48863a0964f5 143 pc.printf(" Length = %d\r\n", msg.len);
38domo 0:48863a0964f5 144 pc.printf(" Data =");
38domo 0:48863a0964f5 145 for(int i = 0; i < msg.len; i++)
38domo 0:48863a0964f5 146 pc.printf(" 0x%.2X", msg.data[i]);
38domo 0:48863a0964f5 147 pc.printf("\r\n");
38domo 0:48863a0964f5 148 serial7.printf(" Can message received ok\n");
38domo 0:48863a0964f5 149 serial7.printf("ID = 0x%.3x Data= ", msg.id);
38domo 0:48863a0964f5 150 for(int i = 0; i < msg.len; i++)
38domo 0:48863a0964f5 151 serial7.printf(" 0x%.2X", msg.data[i]);
38domo 0:48863a0964f5 152 serial7.printf("\r\n");
38domo 0:48863a0964f5 153
38domo 0:48863a0964f5 154 sprintf((char*)text2, "ID: %d", msg.id);
38domo 0:48863a0964f5 155 //BSP_LCD_DisplayStringAt(2, LINE(7), (uint8_t *)&text2, LEFT_MODE);
38domo 0:48863a0964f5 156 sprintf((char*)text2, "Type: %d", msg.type);
38domo 0:48863a0964f5 157 //BSP_LCD_DisplayStringAt(2, LINE(8), (uint8_t *)&text2, LEFT_MODE);
38domo 0:48863a0964f5 158 sprintf((char*)text2, "Format: %d", msg.format);
38domo 0:48863a0964f5 159 //BSP_LCD_DisplayStringAt(2, LINE(9), (uint8_t *)&text2, LEFT_MODE);
38domo 0:48863a0964f5 160 sprintf((char*)text2, "Length: %d", msg.len);
38domo 0:48863a0964f5 161 //BSP_LCD_DisplayStringAt(2, LINE(10), (uint8_t *)&text2, LEFT_MODE);
38domo 0:48863a0964f5 162 sprintf((char*)text2, "Data: %d", msg.data[0]);
38domo 0:48863a0964f5 163 //BSP_LCD_DisplayStringAt(2, LINE(11), (uint8_t *)&text2, LEFT_MODE);
38domo 0:48863a0964f5 164 }
38domo 0:48863a0964f5 165
38domo 0:48863a0964f5 166 /** -----------------------------------------------------------------------------------------
38domo 0:48863a0964f5 167 * @brief Handles received CAN messages
38domo 0:48863a0964f5 168 * @note Called on 'CAN message received' interrupt.
38domo 0:48863a0964f5 169 */
38domo 0:48863a0964f5 170 void onCanReceived(void)
38domo 0:48863a0964f5 171 { can.read(rxMsg);
38domo 0:48863a0964f5 172 pc.printf("-------------------------------------\r\n");
38domo 0:48863a0964f5 173 pc.printf("CAN message received\r\n");
38domo 0:48863a0964f5 174 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE);
38domo 0:48863a0964f5 175 printMsg(rxMsg,1);
38domo 0:48863a0964f5 176 serial7.printf("ID: 0x%.3x ", rxMsg.id);
38domo 0:48863a0964f5 177 serial7.printf("D: ");
38domo 0:48863a0964f5 178 for(int i = 0; i < rxMsg.len; i++)
38domo 0:48863a0964f5 179 serial7.printf(" 0x%.2X", rxMsg.data[i]);
38domo 0:48863a0964f5 180 serial7.printf("\r\n");
38domo 0:48863a0964f5 181 if (rxMsg.id == RX_ID) {
38domo 0:48863a0964f5 182 // extract data from the received CAN message
38domo 0:48863a0964f5 183 // in the same order as it was added on the transmitter side
38domo 0:48863a0964f5 184 rxMsg >> counter;
38domo 0:48863a0964f5 185 rxMsg >> voltage;
38domo 0:48863a0964f5 186 pc.printf(" counter = %d\r\n", counter);
38domo 0:48863a0964f5 187 pc.printf(" voltage = %e V\r\n", voltage);
38domo 0:48863a0964f5 188 }
38domo 0:48863a0964f5 189 timer.start(); // to transmit next message in main
38domo 0:48863a0964f5 190 }
38domo 0:48863a0964f5 191 // ---------------------------------------------------
38domo 0:48863a0964f5 192 void pc_recv()
38domo 0:48863a0964f5 193 { if(serial7.readable())
38domo 0:48863a0964f5 194 { buffer[i]=(serial7.getc());
38domo 0:48863a0964f5 195 if (buffer[i] == '\n') {
38domo 0:48863a0964f5 196 serial7.printf("%s",buffer);
38domo 0:48863a0964f5 197 len = 0;
38domo 0:48863a0964f5 198 idx_ser =0;
38domo 0:48863a0964f5 199 recv_ser = 1;
38domo 0:48863a0964f5 200 }
38domo 0:48863a0964f5 201 idx_ser++;
38domo 0:48863a0964f5 202 }
38domo 0:48863a0964f5 203 }
38domo 0:48863a0964f5 204
38domo 0:48863a0964f5 205 // ------------------------------------------------------------------------------------------
38domo 0:48863a0964f5 206 int main()
38domo 0:48863a0964f5 207 { pc.baud(115200);
38domo 0:48863a0964f5 208 //serial2.baud(115200); // required for tasmota
38domo 0:48863a0964f5 209 serial2.baud(57600); // required for UDP bridge
38domo 0:48863a0964f5 210 serial7.baud(115200); // required for tasmota
38domo 0:48863a0964f5 211 //serial7.attach(&pc_recv, Serial::RxIrq);
38domo 0:48863a0964f5 212
38domo 0:48863a0964f5 213 // config can --------------------------------------
38domo 0:48863a0964f5 214 can.frequency(125000); // set CAN bit rate to 125 kbps
38domo 0:48863a0964f5 215 //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID
38domo 0:48863a0964f5 216 //-- can.attach(onCanReceived); // attach ISR to handle received messages
38domo 0:48863a0964f5 217 #if defined(BOARD1)
38domo 0:48863a0964f5 218 timer.start(); // start timer
38domo 0:48863a0964f5 219 pc.printf("CAN_Hello board #1\r\n");
38domo 0:48863a0964f5 220 #else
38domo 0:48863a0964f5 221 pc.printf("CAN_Hello board #2\r\n");
38domo 0:48863a0964f5 222 #endif
38domo 0:48863a0964f5 223 buffer[0] = '\0';
38domo 0:48863a0964f5 224 printf("\nInit SDCard ...\n");
38domo 0:48863a0964f5 225 mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib
38domo 0:48863a0964f5 226 // reaf following datas
38domo 0:48863a0964f5 227 // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters
38domo 0:48863a0964f5 228 // store local variables from sd
38domo 0:48863a0964f5 229 //extern char gsStreamIPdatas[];
38domo 0:48863a0964f5 230 //extern char ethernet_actif[] ;
38domo 0:48863a0964f5 231 //extern char wifi_actif[];
38domo 0:48863a0964f5 232 //extern char can_actif[];
38domo 0:48863a0964f5 233 //extern char serial_actif[];
38domo 0:48863a0964f5 234 printf("\nFin init SDCard ...\n");
38domo 0:48863a0964f5 235 BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD
38domo 0:48863a0964f5 236 uint8_t text[300];
38domo 0:48863a0964f5 237 printf("Start Prog\n");
38domo 0:48863a0964f5 238 std::string temp1;
38domo 0:48863a0964f5 239 std::string temp2;
38domo 0:48863a0964f5 240
38domo 0:48863a0964f5 241 //lastSuccessfulUploadTime is used for upload frequency.
38domo 0:48863a0964f5 242 time_t lastSuccessfulUploadTime = 0;
38domo 0:48863a0964f5 243 printf("\n Init touchJPA1 ...\n");
38domo 0:48863a0964f5 244 int yy;
38domo 0:48863a0964f5 245 printf("\n Init initDisplayTemp ...\n");
38domo 0:48863a0964f5 246 yy = initDisplayTemp(); // from guijpa.cpp - Init display
38domo 0:48863a0964f5 247 printf("\ninit touchInitJPA1 ...\n");
38domo 0:48863a0964f5 248 yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen
38domo 0:48863a0964f5 249 yy = touchInitGuiJPA1(); // from touchscreen.cpp
38domo 0:48863a0964f5 250 printf("\ninit initDatasGuiJPA ...\n");
38domo 0:48863a0964f5 251 yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons
38domo 0:48863a0964f5 252 ////lcd.printf("Starting...");
38domo 0:48863a0964f5 253 printf("Starting...\n");
38domo 0:48863a0964f5 254 lastToucheTime = time(NULL);
38domo 0:48863a0964f5 255 char data[5];
38domo 0:48863a0964f5 256 // main loop ---------------------------------------------------
38domo 0:48863a0964f5 257 while (true) {
38domo 0:48863a0964f5 258 // lecture sur port serie from tasmota
38domo 0:48863a0964f5 259 if(serial7.readable())
38domo 0:48863a0964f5 260 { buffer[i]=(serial7.getc());
38domo 0:48863a0964f5 261 serial7.printf("%c",buffer[i]);
38domo 0:48863a0964f5 262 if (buffer[i] == '\n') {
38domo 0:48863a0964f5 263 serial7.printf("%s",buffer);
38domo 0:48863a0964f5 264 len = 0;
38domo 0:48863a0964f5 265 idx_ser =0;
38domo 0:48863a0964f5 266 recv_ser = 1;
38domo 0:48863a0964f5 267 }
38domo 0:48863a0964f5 268 idx_ser++;
38domo 0:48863a0964f5 269 }
38domo 0:48863a0964f5 270 if ( recv_ser == 1)
38domo 0:48863a0964f5 271 {serial7.printf("sent: %s",buffer);
38domo 0:48863a0964f5 272 pc.printf("sent: %s",buffer);
38domo 0:48863a0964f5 273 recv_ser =0;
38domo 0:48863a0964f5 274 }
38domo 0:48863a0964f5 275
38domo 0:48863a0964f5 276 // timer send can
38domo 0:48863a0964f5 277 if(timer.read_ms() >= 1000) // check for timeout
38domo 0:48863a0964f5 278 { timer.stop(); // stop the timer
38domo 0:48863a0964f5 279 timer.reset(); // reset the timer
38domo 0:48863a0964f5 280 counter++; // increment the counter
38domo 0:48863a0964f5 281 voltage = (analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input
38domo 0:48863a0964f5 282 txMsg.clear(); // clear the Tx message storage
38domo 0:48863a0964f5 283 //txMsg.id = TX_ID; // set ID
38domo 0:48863a0964f5 284 txMsg.id = 0x18881001;//TX_ID; // set the message ID
38domo 0:48863a0964f5 285 txMsg.format = CANExtended ; //extended
38domo 0:48863a0964f5 286 // We are about to transmit two data items to the CAN bus.
38domo 0:48863a0964f5 287 // counter: uint_8 (unsigned eight bits int) value (one byte).
38domo 0:48863a0964f5 288 // voltage: floating point value (four bytes).
38domo 0:48863a0964f5 289 // So the total length of payload data is five bytes.
38domo 0:48863a0964f5 290 // We'll use the "<<" (append) operator to add data to the CAN message.
38domo 0:48863a0964f5 291 // The usage is same as of the similar C++ io-stream operators.
38domo 0:48863a0964f5 292 // NOTE: The data length of CAN message is automatically updated when using "<<" operators.
38domo 0:48863a0964f5 293 txMsg << counter << voltage; // append data (total data length must be <= 8 bytes!)
38domo 0:48863a0964f5 294
38domo 0:48863a0964f5 295 if(can.write(txMsg)) // transmit message
38domo 0:48863a0964f5 296 { //if(can->write(txMsg)) { // transmit the CAN message
38domo 0:48863a0964f5 297 //led = OFF; // turn the LED off
38domo 0:48863a0964f5 298 pc.printf("-------------------------------------\r\n");
38domo 0:48863a0964f5 299 pc.printf("CAN message sent\r\n");
38domo 0:48863a0964f5 300 printMsg(txMsg,0);
38domo 0:48863a0964f5 301 pc.printf(" counter = %d\r\n", counter);
38domo 0:48863a0964f5 302 pc.printf(" voltage = %e V\r\n", voltage);
38domo 0:48863a0964f5 303 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
38domo 0:48863a0964f5 304 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
38domo 0:48863a0964f5 305 }
38domo 0:48863a0964f5 306 else
38domo 0:48863a0964f5 307 { pc.printf("Transmission error\r\n");
38domo 0:48863a0964f5 308 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
38domo 0:48863a0964f5 309 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
38domo 0:48863a0964f5 310 }
38domo 0:48863a0964f5 311 //timer.start(); // insert transmission lag
38domo 0:48863a0964f5 312 } // end if timer
38domo 0:48863a0964f5 313 //touch screen
38domo 0:48863a0964f5 314 int xx = touchJPA1(); //
38domo 0:48863a0964f5 315 if (xx > 0)
38domo 0:48863a0964f5 316 { pc.printf("Touche appuyee %d \r\n",xx);
38domo 0:48863a0964f5 317 // send data to serial bridge tasmota
38domo 0:48863a0964f5 318 serial2.printf(" Touche %d appuyee to Tasmota", xx);
38domo 0:48863a0964f5 319 serial7.printf(" Touche %d appuyee to Tasmota", xx);
38domo 0:48863a0964f5 320 if (xx ==4 )
38domo 0:48863a0964f5 321 { // send trame to can
38domo 0:48863a0964f5 322 if(can.write(txMsg)) // transmit message
38domo 0:48863a0964f5 323 { //if(can->write(txMsg)) { // transmit the CAN message
38domo 0:48863a0964f5 324 //led = OFF; // turn the LED off
38domo 0:48863a0964f5 325 pc.printf("-------------------------------------\r\n");
38domo 0:48863a0964f5 326 pc.printf("CAN message sent\r\n");
38domo 0:48863a0964f5 327 printMsg(txMsg,0);
38domo 0:48863a0964f5 328 pc.printf(" counter = %d\r\n", counter);
38domo 0:48863a0964f5 329 pc.printf(" voltage = %e V\r\n", voltage);
38domo 0:48863a0964f5 330 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
38domo 0:48863a0964f5 331 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
38domo 0:48863a0964f5 332 serial7.printf(" send trame can ok");
38domo 0:48863a0964f5 333 }
38domo 0:48863a0964f5 334 else
38domo 0:48863a0964f5 335 { pc.printf("Transmission error\r\n");
38domo 0:48863a0964f5 336 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
38domo 0:48863a0964f5 337 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
38domo 0:48863a0964f5 338 }
38domo 0:48863a0964f5 339 }
38domo 0:48863a0964f5 340 pc.printf("data sent to tasmota serial bridge \n");
38domo 0:48863a0964f5 341 // data sent to ethernet
38domo 0:48863a0964f5 342 xx = sendTouchJPA(xx);
38domo 0:48863a0964f5 343
38domo 0:48863a0964f5 344 lastToucheTime = time(NULL);
38domo 0:48863a0964f5 345
38domo 0:48863a0964f5 346 }
38domo 0:48863a0964f5 347 else
38domo 0:48863a0964f5 348 { lastToucheTime = 0;
38domo 0:48863a0964f5 349 } // send mqtt
38domo 0:48863a0964f5 350 // Update sensor data to GroveStreams
38domo 0:48863a0964f5 351 seconds = time(NULL);
38domo 0:48863a0964f5 352 if(seconds - lastSuccessfulUploadTime > updateFrequency) {
38domo 0:48863a0964f5 353 ////lcd.clear();
38domo 0:48863a0964f5 354 ////lcd.printf("Getting Samples...");
38domo 0:48863a0964f5 355 printf("Getting Samples...\n");
38domo 0:48863a0964f5 356 //Assemble the samples into URL parameters which are seperated with the "&" character
38domo 0:48863a0964f5 357 // Example: &s1=6.2&s2=78.231
38domo 0:48863a0964f5 358 int temperature = adc_temp.read() * 100.0f;
38domo 0:48863a0964f5 359 int voltage = adc_vref.read() * 100.0f;
38domo 0:48863a0964f5 360 char samples[64] = {0};
38domo 0:48863a0964f5 361 sprintf(samples, "&%s=%d&%s=%d", gsStreamId1, voltage, gsStreamId2, temperature);
38domo 0:48863a0964f5 362 //Append on command requests (request stream values)
38domo 0:48863a0964f5 363 //This will indicate to GroveStreams to return the last value
38domo 0:48863a0964f5 364 // of each request stream during the sample upload
38domo 0:48863a0964f5 365 strcat(samples, "&rsid=freq&rsid=led");
38domo 0:48863a0964f5 366 char resultBuffer[700]= {0};
38domo 0:48863a0964f5 367 //Sending Samples (and returning current command stream values)
38domo 0:48863a0964f5 368 time_t connectAttemptTime = time(NULL);
38domo 0:48863a0964f5 369 int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); //receive mqtt
38domo 0:48863a0964f5 370
38domo 0:48863a0964f5 371 if (sendResult == 0) {
38domo 0:48863a0964f5 372 ////lcd.printf("Send Successful");
38domo 0:48863a0964f5 373 printf("Send Successful\n");
38domo 0:48863a0964f5 374 lastSuccessfulUploadTime = connectAttemptTime;
38domo 0:48863a0964f5 375 //Handle command streams
38domo 0:48863a0964f5 376 if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') {
38domo 0:48863a0964f5 377 MbedJSONValue mbedJson;
38domo 0:48863a0964f5 378 parse(mbedJson, resultBuffer);
38domo 0:48863a0964f5 379 sprintf((char*)text, "HTTP string : %s\n", resultBuffer);
38domo 0:48863a0964f5 380 //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 381 if (mbedJson.hasMember("Temp1")) {
38domo 0:48863a0964f5 382 int pp=setTemp1(mbedJson["Temp1"].get<std::string>());
38domo 0:48863a0964f5 383 }
38domo 0:48863a0964f5 384 if (mbedJson.hasMember("Temp2")) {
38domo 0:48863a0964f5 385 int tt=setTemp2(mbedJson["Temp2"].get<std::string>());
38domo 0:48863a0964f5 386 }
38domo 0:48863a0964f5 387 if (mbedJson.hasMember("led")) {
38domo 0:48863a0964f5 388 //Change LED
38domo 0:48863a0964f5 389 myled = mbedJson["led"].get<bool>() ? 1 : 0;
38domo 0:48863a0964f5 390 ////lcd.printf("LED: %s", mbedJson["led"].get<bool>() ? "On" : "Off");
38domo 0:48863a0964f5 391 printf("LED: %s\n", mbedJson["led"].get<bool>() ? "On" : "Off");
38domo 0:48863a0964f5 392 }
38domo 0:48863a0964f5 393 }
38domo 0:48863a0964f5 394 }
38domo 0:48863a0964f5 395 }
38domo 0:48863a0964f5 396
38domo 0:48863a0964f5 397 }
38domo 0:48863a0964f5 398 }
38domo 0:48863a0964f5 399
38domo 0:48863a0964f5 400