Temperature Sensor DHT readings to FRDMk64f

Dependencies:   DHT

Fork of Hexi_Blinky_Example by Hexiwear

Committer:
roborags
Date:
Thu Apr 27 15:10:13 2017 +0000
Revision:
18:293c2885af81
Parent:
17:690d692b29cb
Child:
19:ffd78d964d9f
Final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roborags 14:02ddfa711646 1
dan 0:7dec7e9ac085 2 #include "mbed.h"
roborags 14:02ddfa711646 3 #include "ESP8266.h" // Include header file from Author: Antonio Quevedo
roborags 14:02ddfa711646 4 #include "math.h"
roborags 15:67a7cca7ae06 5 #include "DHT.h"
roborags 18:293c2885af81 6 #include "GT511C3.hpp"
roborags 14:02ddfa711646 7 #include <string>
roborags 14:02ddfa711646 8
roborags 15:67a7cca7ae06 9 #define APIKEY JJAOBK32WOINKT00 //Put "Write key" of your channel in thingspeak.com
roborags 14:02ddfa711646 10 #define IP "184.106.153.149" // IP Address of "api.thingspeak.com\"
roborags 18:293c2885af81 11 #define WIFI_SSID "Redmi"
roborags 18:293c2885af81 12 #define WIFI_PASS "akash12345"
roborags 18:293c2885af81 13 #define FPS_ENROLL_PASS "Rags\n"
roborags 15:67a7cca7ae06 14
roborags 15:67a7cca7ae06 15 Serial FRDM_UART_Debug(USBTX,USBRX);
roborags 15:67a7cca7ae06 16
roborags 16:39e45e59677c 17 ESP8266 ESP_8266_UART(PTC15, PTC14, 115200); // UART for ESP8266 Wifi module
roborags 15:67a7cca7ae06 18 // Options are TX-RX - PTB11 - PTB10 , PTC17 - PTC16 , PTC15 - PTC14
roborags 14:02ddfa711646 19
roborags 15:67a7cca7ae06 20 SPI SPI_Bus(PTD2,PTD3,PTD1); // (MOSI MISO CLK)setup SPI interface
roborags 17:690d692b29cb 21 DigitalOut SPI_CS_AMM(PTA2);
roborags 17:690d692b29cb 22 DigitalOut SPI_CS_VOLT(PTB9);
roborags 14:02ddfa711646 23
roborags 15:67a7cca7ae06 24 I2C I2C_Bus(PTE25,PTE24);
roborags 15:67a7cca7ae06 25
roborags 16:39e45e59677c 26 AnalogIn AN_Thermo(PTB2); // Thermocouple Analog Input
roborags 15:67a7cca7ae06 27
roborags 17:690d692b29cb 28 DigitalIn DG_Motion(PTC2); // Motion module Digital Input
roborags 14:02ddfa711646 29
roborags 17:690d692b29cb 30 DHT DHT_Temp_Hum(PTC4,DHT22); //DHT Sensor
roborags 14:02ddfa711646 31
roborags 18:293c2885af81 32 GT511C3 FPS(PTC17, PTC16);
roborags 18:293c2885af81 33
roborags 15:67a7cca7ae06 34 const int Light_I2C_Addr = 0x88;
roborags 15:67a7cca7ae06 35
roborags 15:67a7cca7ae06 36 char ESP_8266_CMD_Send[255],ESP_8266_CMD_Recv[1000]; //ESP_8266_CMD_Send = string used to send command to ESP8266 & ESP_8266_CMD_Recv = string used to receive response from ESP8266
roborags 14:02ddfa711646 37
roborags 15:67a7cca7ae06 38 float Amm_Out = 0;
roborags 15:67a7cca7ae06 39 float Volt_Out = 0;
roborags 15:67a7cca7ae06 40 float Light_Out = 0;
roborags 15:67a7cca7ae06 41 float Thermo_Out = 0;
roborags 15:67a7cca7ae06 42 float Temp_Out = 0;
roborags 15:67a7cca7ae06 43 float Hum_Out = 0;
roborags 15:67a7cca7ae06 44 int Motion_Out = 0;
roborags 15:67a7cca7ae06 45 int Finger_Out = 0;
roborags 15:67a7cca7ae06 46 float Pres_Out = 0;
roborags 18:293c2885af81 47 bool FPS_Auth = false;
dan 0:7dec7e9ac085 48
roborags 14:02ddfa711646 49
roborags 15:67a7cca7ae06 50 void ESP_8266_Init(void); // Function used to initialize ESP8266 wifi module
roborags 15:67a7cca7ae06 51 void ESP_8266_TX_Data(void); // Function used to connect with thingspeak.com and update channel using ESP8266 wifi module
roborags 18:293c2885af81 52 void FPS_Func(void);
roborags 18:293c2885af81 53 int FPS_Wait_Time(int press,bool Det_Mot, unsigned long *ms_time);
roborags 14:02ddfa711646 54
roborags 14:02ddfa711646 55 int main()
roborags 14:02ddfa711646 56 {
roborags 15:67a7cca7ae06 57 int SPI_High_byte = 0;
roborags 15:67a7cca7ae06 58 int SPI_Low_byte = 0;
roborags 15:67a7cca7ae06 59 float Temp_f_1 = 0.00;
roborags 15:67a7cca7ae06 60 float Temp_f_2 = 0.00;
roborags 15:67a7cca7ae06 61 int Temp_i_1 = 0;
roborags 15:67a7cca7ae06 62 int Temp_i_2 = 0;
roborags 15:67a7cca7ae06 63 int Temp_i_3 = 0;
roborags 18:293c2885af81 64 int Temp_i_4 = 0;
roborags 15:67a7cca7ae06 65 char I2C_Cmd[3];
roborags 15:67a7cca7ae06 66 int loop_count = 0;
roborags 18:293c2885af81 67 int FPS_Ret = 0;
roborags 18:293c2885af81 68 int FPS_Attempt = 1;
roborags 18:293c2885af81 69 int FPS_Enroll_ID = 0;
roborags 18:293c2885af81 70 unsigned long FPS_Param = 0;
roborags 18:293c2885af81 71 unsigned short FPS_Resp = 0;
roborags 18:293c2885af81 72 char FPS_Enroll_Pass[20];
roborags 18:293c2885af81 73 unsigned long FPS_Delay = 0;
roborags 14:02ddfa711646 74
roborags 15:67a7cca7ae06 75 FRDM_UART_Debug.baud(115200); // Baud rate used for communicating with Tera-term on PC
roborags 15:67a7cca7ae06 76
roborags 15:67a7cca7ae06 77 ESP_8266_Init();
roborags 14:02ddfa711646 78
roborags 15:67a7cca7ae06 79 SPI_Bus.format(8,0);
roborags 15:67a7cca7ae06 80 SPI_Bus.frequency(1000000);
roborags 15:67a7cca7ae06 81
roborags 15:67a7cca7ae06 82 I2C_Bus.frequency(100000); // set required i2c frequency
roborags 15:67a7cca7ae06 83
roborags 18:293c2885af81 84 FPS_Ret = FPS.Open();
roborags 18:293c2885af81 85 if(FPS_Ret == -1)
roborags 18:293c2885af81 86 {
roborags 18:293c2885af81 87 FRDM_UART_Debug.printf("FPS NACK Open\r\n");
roborags 18:293c2885af81 88 }
roborags 18:293c2885af81 89 else
roborags 18:293c2885af81 90 {
roborags 18:293c2885af81 91 FRDM_UART_Debug.printf("FPS Init\r\n");
roborags 18:293c2885af81 92 FRDM_UART_Debug.printf("FPS F/W = %d , ISO_Size = %d , Serial Num = %s\r\n",FPS.FirmwareVersion,FPS.IsoAreaMaxSize,FPS.DeviceSerialNumber);
roborags 18:293c2885af81 93 }
roborags 18:293c2885af81 94
roborags 18:293c2885af81 95 FPS_Ret = FPS.CmosLed(1);
roborags 18:293c2885af81 96 if(FPS_Ret == -1)
roborags 18:293c2885af81 97 {
roborags 18:293c2885af81 98 FRDM_UART_Debug.printf("FPS NACK LED Set\r\n");
roborags 18:293c2885af81 99 }
roborags 18:293c2885af81 100
roborags 18:293c2885af81 101 wait(1);
roborags 18:293c2885af81 102
roborags 18:293c2885af81 103 if(DG_Motion == 1)
roborags 18:293c2885af81 104 {
roborags 18:293c2885af81 105 FRDM_UART_Debug.printf("Motion detected, press Finger within 5 seconds to Start\r\n");
roborags 18:293c2885af81 106
roborags 18:293c2885af81 107 FPS_Delay = 5000;
roborags 18:293c2885af81 108 FPS_Ret = FPS_Wait_Time(1,false,&FPS_Delay);
roborags 18:293c2885af81 109 if(FPS_Ret == 1)
roborags 18:293c2885af81 110 {
roborags 18:293c2885af81 111 FPS_Func();
roborags 18:293c2885af81 112 }
roborags 18:293c2885af81 113 }
roborags 15:67a7cca7ae06 114 FRDM_UART_Debug.printf("Start sampling data\r\n"); // Starting point
roborags 18:293c2885af81 115
roborags 14:02ddfa711646 116 while (1)
roborags 14:02ddfa711646 117 {
roborags 15:67a7cca7ae06 118 Amm_Out = 0;
roborags 15:67a7cca7ae06 119 Volt_Out = 0;
roborags 15:67a7cca7ae06 120 Light_Out = 0;
roborags 15:67a7cca7ae06 121 Thermo_Out = 0;
roborags 15:67a7cca7ae06 122 Temp_Out = 0;
roborags 15:67a7cca7ae06 123 Hum_Out = 0;
roborags 15:67a7cca7ae06 124 Motion_Out = 0;
roborags 15:67a7cca7ae06 125
roborags 15:67a7cca7ae06 126 // Copy Motion values
roborags 15:67a7cca7ae06 127
roborags 15:67a7cca7ae06 128 Motion_Out = DG_Motion;
roborags 15:67a7cca7ae06 129
roborags 15:67a7cca7ae06 130 // Ammeter
roborags 15:67a7cca7ae06 131
roborags 15:67a7cca7ae06 132 SPI_High_byte = 0;
roborags 15:67a7cca7ae06 133 SPI_Low_byte = 0;
roborags 15:67a7cca7ae06 134 Temp_f_1 = 0.00;
roborags 15:67a7cca7ae06 135 Temp_f_2 = 0.00;
roborags 15:67a7cca7ae06 136 Temp_i_1 = 0;
roborags 15:67a7cca7ae06 137 Temp_i_2 = 0;
roborags 15:67a7cca7ae06 138 Temp_i_3 = 0;
roborags 15:67a7cca7ae06 139 I2C_Cmd[0] = 0;
roborags 15:67a7cca7ae06 140 I2C_Cmd[1] = 0;
roborags 15:67a7cca7ae06 141 I2C_Cmd[2] = 0;
roborags 15:67a7cca7ae06 142 loop_count = 0;
roborags 15:67a7cca7ae06 143
roborags 15:67a7cca7ae06 144 SPI_CS_AMM = 0;
roborags 15:67a7cca7ae06 145
roborags 15:67a7cca7ae06 146 SPI_High_byte = SPI_Bus.write(0);
roborags 15:67a7cca7ae06 147 SPI_Low_byte = SPI_Bus.write(0);
roborags 15:67a7cca7ae06 148
roborags 15:67a7cca7ae06 149 SPI_CS_AMM = 1;
roborags 15:67a7cca7ae06 150
roborags 16:39e45e59677c 151 Temp_f_1 = (( SPI_High_byte & 0x1F ) << 7 ) | (( SPI_Low_byte >> 1 ));
roborags 15:67a7cca7ae06 152
roborags 15:67a7cca7ae06 153 Temp_f_2= (float)(( Temp_f_1 * 1.00 ) / 4096.00 ); // Converting to volts
roborags 15:67a7cca7ae06 154
roborags 15:67a7cca7ae06 155 Amm_Out = (float)(( Temp_f_2 - 0.50 ) * 1000.00);
roborags 15:67a7cca7ae06 156
roborags 18:293c2885af81 157 if(FPS_Auth)
roborags 18:293c2885af81 158 FRDM_UART_Debug.printf("Current value = %f mA\r\n", Amm_Out);
roborags 14:02ddfa711646 159 wait_ms(100);
roborags 14:02ddfa711646 160
roborags 15:67a7cca7ae06 161 // Voltmeter
roborags 15:67a7cca7ae06 162
roborags 15:67a7cca7ae06 163 SPI_High_byte = 0;
roborags 15:67a7cca7ae06 164 SPI_Low_byte = 0;
roborags 15:67a7cca7ae06 165 Temp_f_1 = 0.00;
roborags 15:67a7cca7ae06 166 Temp_f_2 = 0.00;
roborags 15:67a7cca7ae06 167 Temp_i_1 = 0;
roborags 15:67a7cca7ae06 168 Temp_i_2 = 0;
roborags 15:67a7cca7ae06 169 Temp_i_3 = 0;
roborags 15:67a7cca7ae06 170 I2C_Cmd[0] = 0;
roborags 15:67a7cca7ae06 171 I2C_Cmd[1] = 0;
roborags 15:67a7cca7ae06 172 I2C_Cmd[2] = 0;
roborags 15:67a7cca7ae06 173 loop_count = 0;
roborags 15:67a7cca7ae06 174
roborags 15:67a7cca7ae06 175 SPI_CS_VOLT = 0;
roborags 15:67a7cca7ae06 176
roborags 15:67a7cca7ae06 177 SPI_High_byte = SPI_Bus.write(0);
roborags 15:67a7cca7ae06 178 SPI_Low_byte = SPI_Bus.write(0);
roborags 15:67a7cca7ae06 179
roborags 15:67a7cca7ae06 180 SPI_CS_VOLT = 1;
roborags 15:67a7cca7ae06 181
roborags 15:67a7cca7ae06 182 Temp_f_1 = ((SPI_High_byte & 0x1f) << 7) | ((SPI_Low_byte >> 1));
roborags 15:67a7cca7ae06 183
roborags 15:67a7cca7ae06 184 Temp_f_2 = (float)((Temp_f_1 * 33) / 4096); // show value in volts.
roborags 15:67a7cca7ae06 185
roborags 15:67a7cca7ae06 186 Volt_Out = (float)(Temp_f_2 - 16.5);
roborags 14:02ddfa711646 187
roborags 18:293c2885af81 188 if(FPS_Auth)
roborags 18:293c2885af81 189 FRDM_UART_Debug.printf("Voltage value = %f V\r\n", Volt_Out);
roborags 15:67a7cca7ae06 190 wait_ms(100);
roborags 15:67a7cca7ae06 191
roborags 15:67a7cca7ae06 192 //ambient light
roborags 15:67a7cca7ae06 193
roborags 15:67a7cca7ae06 194 SPI_High_byte = 0;
roborags 15:67a7cca7ae06 195 SPI_Low_byte = 0;
roborags 15:67a7cca7ae06 196 Temp_f_1 = 0.00;
roborags 15:67a7cca7ae06 197 Temp_f_2 = 0.00;
roborags 15:67a7cca7ae06 198 Temp_i_1 = 0;
roborags 15:67a7cca7ae06 199 Temp_i_2 = 0;
roborags 15:67a7cca7ae06 200 Temp_i_3 = 0;
roborags 15:67a7cca7ae06 201 I2C_Cmd[0] = 0;
roborags 15:67a7cca7ae06 202 I2C_Cmd[1] = 0;
roborags 15:67a7cca7ae06 203 I2C_Cmd[2] = 0;
roborags 15:67a7cca7ae06 204 loop_count = 0;
roborags 15:67a7cca7ae06 205
roborags 15:67a7cca7ae06 206 I2C_Cmd[0] = 0x01; //configuration register
roborags 15:67a7cca7ae06 207 I2C_Cmd[1]= 0xCC; //configuration data
roborags 15:67a7cca7ae06 208 I2C_Cmd[2]= 0x01; //configuration data
roborags 15:67a7cca7ae06 209
roborags 15:67a7cca7ae06 210 I2C_Bus.write(Light_I2C_Addr, I2C_Cmd, 3);
roborags 15:67a7cca7ae06 211
roborags 15:67a7cca7ae06 212 I2C_Cmd[0] = 0x00; // data register
roborags 15:67a7cca7ae06 213
roborags 15:67a7cca7ae06 214 I2C_Bus.write(Light_I2C_Addr, I2C_Cmd, 1);
roborags 15:67a7cca7ae06 215
roborags 14:02ddfa711646 216 wait_ms(100);
roborags 14:02ddfa711646 217
roborags 15:67a7cca7ae06 218 I2C_Bus.read(Light_I2C_Addr, I2C_Cmd, 2);
roborags 14:02ddfa711646 219
roborags 15:67a7cca7ae06 220 Temp_i_1= I2C_Cmd[0]>>4;
roborags 15:67a7cca7ae06 221 Temp_i_2= (I2C_Cmd[0]-(Temp_i_1<<4))*256+I2C_Cmd[1];
roborags 15:67a7cca7ae06 222
roborags 16:39e45e59677c 223 for(loop_count = 0,Temp_i_3 = 1 ; loop_count < Temp_i_1 ; Temp_i_3 = Temp_i_3 * 2,loop_count++);
roborags 15:67a7cca7ae06 224
roborags 15:67a7cca7ae06 225 Light_Out= (Temp_i_2 * Temp_i_3) / 100;
roborags 15:67a7cca7ae06 226
roborags 18:293c2885af81 227 if(FPS_Auth)
roborags 18:293c2885af81 228 FRDM_UART_Debug.printf("Lux = %.2f\n\r", Light_Out);
roborags 15:67a7cca7ae06 229 wait_ms(100);
roborags 15:67a7cca7ae06 230
roborags 15:67a7cca7ae06 231 // Thermocouple
roborags 15:67a7cca7ae06 232
roborags 15:67a7cca7ae06 233 SPI_High_byte = 0;
roborags 15:67a7cca7ae06 234 SPI_Low_byte = 0;
roborags 15:67a7cca7ae06 235 Temp_f_1 = 0.00;
roborags 15:67a7cca7ae06 236 Temp_f_2 = 0.00;
roborags 15:67a7cca7ae06 237 Temp_i_1 = 0;
roborags 15:67a7cca7ae06 238 Temp_i_2 = 0;
roborags 15:67a7cca7ae06 239 Temp_i_3 = 0;
roborags 15:67a7cca7ae06 240 I2C_Cmd[0] = 0;
roborags 15:67a7cca7ae06 241 I2C_Cmd[1] = 0;
roborags 15:67a7cca7ae06 242 I2C_Cmd[2] = 0;
roborags 15:67a7cca7ae06 243 loop_count = 0;
roborags 15:67a7cca7ae06 244
roborags 15:67a7cca7ae06 245 Temp_f_1 = AN_Thermo.read_u16();
roborags 15:67a7cca7ae06 246
roborags 15:67a7cca7ae06 247 Temp_f_1 = (( Temp_f_1 / 65536 ) * 330);
roborags 15:67a7cca7ae06 248
roborags 15:67a7cca7ae06 249 Thermo_Out = Temp_f_1;
roborags 15:67a7cca7ae06 250
roborags 18:293c2885af81 251 if(FPS_Auth)
roborags 18:293c2885af81 252 FRDM_UART_Debug.printf("Thermocouple volt diff = %.2f C\r\n",Thermo_Out);
roborags 14:02ddfa711646 253 wait_ms(100);
roborags 14:02ddfa711646 254
roborags 15:67a7cca7ae06 255 // Temp and Humidity
roborags 15:67a7cca7ae06 256
roborags 15:67a7cca7ae06 257 SPI_High_byte = 0;
roborags 15:67a7cca7ae06 258 SPI_Low_byte = 0;
roborags 15:67a7cca7ae06 259 Temp_f_1 = 0.00;
roborags 15:67a7cca7ae06 260 Temp_f_2 = 0.00;
roborags 15:67a7cca7ae06 261 Temp_i_1 = 0;
roborags 15:67a7cca7ae06 262 Temp_i_2 = 0;
roborags 15:67a7cca7ae06 263 Temp_i_3 = 0;
roborags 15:67a7cca7ae06 264 I2C_Cmd[0] = 0;
roborags 15:67a7cca7ae06 265 I2C_Cmd[1] = 0;
roborags 15:67a7cca7ae06 266 I2C_Cmd[2] = 0;
roborags 15:67a7cca7ae06 267 loop_count = 0;
roborags 15:67a7cca7ae06 268
roborags 15:67a7cca7ae06 269 Temp_i_1 = DHT_Temp_Hum.readData();
roborags 15:67a7cca7ae06 270 if (Temp_i_1 == 0) // Read success
roborags 15:67a7cca7ae06 271 {
roborags 16:39e45e59677c 272 //wait_ms(1000);
roborags 15:67a7cca7ae06 273 Temp_f_1 = DHT_Temp_Hum.ReadTemperature(FARENHEIT);
roborags 15:67a7cca7ae06 274 Temp_f_2 = DHT_Temp_Hum.ReadHumidity();
roborags 15:67a7cca7ae06 275 }
roborags 15:67a7cca7ae06 276 else // Read failure
roborags 15:67a7cca7ae06 277 {
roborags 15:67a7cca7ae06 278 Temp_f_1 = 0;
roborags 15:67a7cca7ae06 279 Temp_f_2 = 0;
roborags 15:67a7cca7ae06 280 }
roborags 15:67a7cca7ae06 281
roborags 15:67a7cca7ae06 282 Temp_Out = Temp_f_1;
roborags 15:67a7cca7ae06 283 Hum_Out = Temp_f_2;
roborags 15:67a7cca7ae06 284
roborags 18:293c2885af81 285 if(FPS_Auth)
roborags 18:293c2885af81 286 FRDM_UART_Debug.printf("Temperature = %4.2f F , Humidity = %4.2f \r\n",Temp_Out,Hum_Out);
roborags 15:67a7cca7ae06 287 wait_ms(100);
roborags 15:67a7cca7ae06 288
roborags 18:293c2885af81 289 //if(FPS_Auth)
roborags 18:293c2885af81 290 FRDM_UART_Debug.printf("Sending Data to Server\r\n");
roborags 15:67a7cca7ae06 291 ESP_8266_TX_Data();
roborags 14:02ddfa711646 292
roborags 18:293c2885af81 293 FPS_Delay = 15000;
roborags 18:293c2885af81 294
roborags 18:293c2885af81 295 FPS_Check_Again:
roborags 18:293c2885af81 296 FPS_Ret = FPS_Wait_Time(1,true,&FPS_Delay);
roborags 18:293c2885af81 297 if(FPS_Ret == 1)
roborags 18:293c2885af81 298 {
roborags 18:293c2885af81 299 FRDM_UART_Debug.printf("Motion detected, press Finger within %d seconds to Authenticate and display data\r\n",FPS_Delay);
roborags 18:293c2885af81 300 FPS_Ret = FPS_Wait_Time(1,false,&FPS_Delay);
roborags 18:293c2885af81 301 if(FPS_Ret == 1)
roborags 18:293c2885af81 302 {
roborags 18:293c2885af81 303 FPS_Func();
roborags 18:293c2885af81 304 goto FPS_Check_Again;
roborags 18:293c2885af81 305 }
roborags 18:293c2885af81 306 else if(FPS_Delay > 99)
roborags 18:293c2885af81 307 {
roborags 18:293c2885af81 308 FRDM_UART_Debug.printf("Remaining delay is %d\r\n",FPS_Delay);
roborags 18:293c2885af81 309 goto FPS_Check_Again;
roborags 18:293c2885af81 310 }
roborags 18:293c2885af81 311 }
roborags 18:293c2885af81 312 else if(FPS_Delay > 99)
roborags 18:293c2885af81 313 {
roborags 18:293c2885af81 314 FRDM_UART_Debug.printf("Remaining delay is %d\r\n",FPS_Delay);
roborags 18:293c2885af81 315 goto FPS_Check_Again;
roborags 18:293c2885af81 316 }
roborags 18:293c2885af81 317
roborags 18:293c2885af81 318 //wait(15);
roborags 16:39e45e59677c 319
stevep 4:81cea7a352b0 320 }
dan 0:7dec7e9ac085 321 }
roborags 14:02ddfa711646 322
roborags 18:293c2885af81 323 int FPS_Wait_Time(int press,bool Det_Mot, unsigned long *ms_time)
roborags 18:293c2885af81 324 {
roborags 18:293c2885af81 325 for(;*ms_time>99;)
roborags 18:293c2885af81 326 {
roborags 18:293c2885af81 327 if((FPS.IsPress() == press) || ((Det_Mot == true) && (DG_Motion == 1)))
roborags 18:293c2885af81 328 return 1;
roborags 18:293c2885af81 329 else
roborags 18:293c2885af81 330 {
roborags 18:293c2885af81 331 *ms_time-=100;
roborags 18:293c2885af81 332 wait_ms(100);
roborags 18:293c2885af81 333 }
roborags 18:293c2885af81 334 }
roborags 18:293c2885af81 335 return 0;
roborags 18:293c2885af81 336 /*
roborags 18:293c2885af81 337 for(;(FPS.IsPress() != press);wait_ms(100),*ms_time-=100);
roborags 18:293c2885af81 338 if(*ms_time >= 99)
roborags 18:293c2885af81 339 return 1;
roborags 18:293c2885af81 340 else
roborags 18:293c2885af81 341 return 0;
roborags 18:293c2885af81 342 */
roborags 18:293c2885af81 343 }
roborags 18:293c2885af81 344
roborags 18:293c2885af81 345 void FPS_Func(void)
roborags 18:293c2885af81 346 {
roborags 18:293c2885af81 347 int Temp_i_1 = 0;
roborags 18:293c2885af81 348 int Temp_i_2 = 0;
roborags 18:293c2885af81 349 int Temp_i_3 = 0;
roborags 18:293c2885af81 350 int Temp_i_4 = 0;
roborags 18:293c2885af81 351 int loop_count = 0;
roborags 18:293c2885af81 352 int FPS_Ret = 0;
roborags 18:293c2885af81 353 int FPS_Attempt = 1;
roborags 18:293c2885af81 354 int FPS_Enroll_ID = 0;
roborags 18:293c2885af81 355 unsigned long FPS_Param = 0;
roborags 18:293c2885af81 356 unsigned short FPS_Resp = 0;
roborags 18:293c2885af81 357 unsigned long FPS_Delay = 0;
roborags 18:293c2885af81 358 char FPS_Enroll_Pass[20];
roborags 18:293c2885af81 359
roborags 18:293c2885af81 360 FRDM_UART_Debug.printf("FPS Select Option:\r\n1. Verify ID \r\n2. Enroll ID\r\n3. Delete ID \r\n4. Quit \r\n");
roborags 18:293c2885af81 361 FRDM_UART_Debug.scanf("%d",&Temp_i_4);
roborags 18:293c2885af81 362
roborags 18:293c2885af81 363 switch(Temp_i_4)
roborags 18:293c2885af81 364 {
roborags 18:293c2885af81 365 case 1:
roborags 18:293c2885af81 366
roborags 18:293c2885af81 367 FRDM_UART_Debug.printf("FPS VERIFICATION\r\n");
roborags 18:293c2885af81 368 FRDM_UART_Debug.printf("FPS Press finger to start\r\n");
roborags 18:293c2885af81 369
roborags 18:293c2885af81 370 FPS_Delay = 10000;
roborags 18:293c2885af81 371 FPS_Wait_Time(1,false,&FPS_Delay);
roborags 18:293c2885af81 372
roborags 18:293c2885af81 373 //Verify
roborags 18:293c2885af81 374 FPS_Ret = FPS.Capture(1);
roborags 18:293c2885af81 375 if(FPS_Ret == -1)
roborags 18:293c2885af81 376 {
roborags 18:293c2885af81 377 FRDM_UART_Debug.printf("FPS Verification failed, place finger properly\r\n");
roborags 18:293c2885af81 378 FPS_Auth = false;
roborags 18:293c2885af81 379 goto loop_end;
roborags 18:293c2885af81 380 }
roborags 18:293c2885af81 381
roborags 18:293c2885af81 382 FRDM_UART_Debug.printf("FPS Captured\r\n");
roborags 18:293c2885af81 383
roborags 18:293c2885af81 384 FPS_Ret = FPS.Identify();
roborags 18:293c2885af81 385 if(FPS_Ret != -1)
roborags 18:293c2885af81 386 {
roborags 18:293c2885af81 387 FRDM_UART_Debug.printf("FPS Authentication PASSED with ID = %d \r\n",FPS_Ret);
roborags 18:293c2885af81 388 FPS_Auth = true;
roborags 18:293c2885af81 389 goto loop_end;
roborags 18:293c2885af81 390 }
roborags 18:293c2885af81 391 else
roborags 18:293c2885af81 392 {
roborags 18:293c2885af81 393 FRDM_UART_Debug.printf("FPS Authentication FAILED \r\n");
roborags 18:293c2885af81 394 FPS_Auth = false;
roborags 18:293c2885af81 395 goto loop_end;
roborags 18:293c2885af81 396 }
roborags 18:293c2885af81 397 break;
roborags 18:293c2885af81 398
roborags 18:293c2885af81 399 case 2:
roborags 18:293c2885af81 400 FRDM_UART_Debug.printf("FPS ENROLL\r\n");
roborags 18:293c2885af81 401
roborags 18:293c2885af81 402 for(FPS_Attempt = 3;FPS_Attempt >= 1;FPS_Attempt --)
roborags 18:293c2885af81 403 {
roborags 18:293c2885af81 404 FRDM_UART_Debug.printf("FPS Enter Enroll passoword\r\n");
roborags 18:293c2885af81 405 FRDM_UART_Debug.scanf("%s",&FPS_Enroll_Pass[0]);
roborags 18:293c2885af81 406
roborags 18:293c2885af81 407 if(FPS_Enroll_Pass == FPS_ENROLL_PASS)
roborags 18:293c2885af81 408 {
roborags 18:293c2885af81 409 FRDM_UART_Debug.printf("FPS Wrong Enroll passoword %d attempts left\r\n",FPS_Attempt);
roborags 18:293c2885af81 410 }
roborags 18:293c2885af81 411 else
roborags 18:293c2885af81 412 break;
roborags 18:293c2885af81 413 }
roborags 18:293c2885af81 414
roborags 18:293c2885af81 415 if(FPS_Attempt < 1)
roborags 18:293c2885af81 416 {
roborags 18:293c2885af81 417 FRDM_UART_Debug.printf("FPS Enroll Password authentication failed \r\n");
roborags 18:293c2885af81 418 goto loop_end;
roborags 18:293c2885af81 419 }
roborags 18:293c2885af81 420
roborags 18:293c2885af81 421 FRDM_UART_Debug.printf("FPS Enroll passoword Authenticated\r\n");
roborags 18:293c2885af81 422
roborags 18:293c2885af81 423 for(FPS_Enroll_ID = 0; FPS_Enroll_ID <20 ;FPS_Enroll_ID++)
roborags 18:293c2885af81 424 {
roborags 18:293c2885af81 425 FPS_Ret = FPS.CheckEnrolled(FPS_Enroll_ID);
roborags 18:293c2885af81 426 if(FPS_Ret == 0)
roborags 18:293c2885af81 427 continue;
roborags 18:293c2885af81 428 else
roborags 18:293c2885af81 429 break;
roborags 18:293c2885af81 430 }
roborags 18:293c2885af81 431
roborags 18:293c2885af81 432 FRDM_UART_Debug.printf("FPS Enroll ID %d\r\n",FPS_Enroll_ID);
roborags 18:293c2885af81 433
roborags 18:293c2885af81 434 if(FPS_Enroll_ID < 20)
roborags 18:293c2885af81 435 {
roborags 18:293c2885af81 436 FRDM_UART_Debug.printf("FPS Starting enrolling, place finger on Sensor when LED glows\r\n");
roborags 18:293c2885af81 437
roborags 18:293c2885af81 438 FPS_Ret = FPS.CmosLed(0);
roborags 18:293c2885af81 439 if(FPS_Ret == -1)
roborags 18:293c2885af81 440 {
roborags 18:293c2885af81 441 FRDM_UART_Debug.printf("FPS Enroll Failed try again\r\n");
roborags 18:293c2885af81 442 goto loop_end;
roborags 18:293c2885af81 443 }
roborags 18:293c2885af81 444
roborags 18:293c2885af81 445 FPS_Param = FPS_Enroll_ID;
roborags 18:293c2885af81 446
roborags 18:293c2885af81 447 FPS_Ret = FPS.SendRecv(FPS.CMD_EnrollStart,&FPS_Param,&FPS_Resp);
roborags 18:293c2885af81 448 if((FPS_Ret != 0) || (FPS_Resp != FPS.CMD_Ack))
roborags 18:293c2885af81 449 {
roborags 18:293c2885af81 450 FRDM_UART_Debug.printf("FPS Enroll Failed try again\r\n");
roborags 18:293c2885af81 451 goto loop_end;
roborags 18:293c2885af81 452 }
roborags 18:293c2885af81 453
roborags 18:293c2885af81 454 Temp_i_1 = 1;
roborags 18:293c2885af81 455
roborags 18:293c2885af81 456 for(Temp_i_2 = 1;Temp_i_2 < 10 ; Temp_i_2++)
roborags 18:293c2885af81 457 {
roborags 18:293c2885af81 458 for(;Temp_i_1 <= 3 ; Temp_i_1++,Temp_i_2 = 1)
roborags 18:293c2885af81 459 {
roborags 18:293c2885af81 460 FPS_Delay = 10000;
roborags 18:293c2885af81 461 FPS_Wait_Time(0,false,&FPS_Delay);
roborags 18:293c2885af81 462
roborags 18:293c2885af81 463 FPS_Ret = FPS.CmosLed(1);
roborags 18:293c2885af81 464 if(FPS_Ret == -1)
roborags 18:293c2885af81 465 {
roborags 18:293c2885af81 466 FRDM_UART_Debug.printf("FPS Enroll Failed trying again\r\n");
roborags 18:293c2885af81 467 continue;
roborags 18:293c2885af81 468 }
roborags 18:293c2885af81 469
roborags 18:293c2885af81 470 for(Temp_i_3 = 1;Temp_i_3 <= 10;Temp_i_3++)
roborags 18:293c2885af81 471 {
roborags 18:293c2885af81 472
roborags 18:293c2885af81 473 FRDM_UART_Debug.printf("FPS Place finger on Sensor NOW %d\r\n",Temp_i_1);
roborags 18:293c2885af81 474 FPS_Delay = 10000;
roborags 18:293c2885af81 475 FPS_Wait_Time(1,false,&FPS_Delay);
roborags 18:293c2885af81 476
roborags 18:293c2885af81 477 if(FPS.Capture(1) == 0)
roborags 18:293c2885af81 478 break;
roborags 18:293c2885af81 479
roborags 18:293c2885af81 480 wait_ms(500);
roborags 18:293c2885af81 481 }
roborags 18:293c2885af81 482
roborags 18:293c2885af81 483 if(Temp_i_2 > 10)
roborags 18:293c2885af81 484 {
roborags 18:293c2885af81 485 FRDM_UART_Debug.printf("FPS Enroll Failed trying again\r\n");
roborags 18:293c2885af81 486 continue;
roborags 18:293c2885af81 487 }
roborags 18:293c2885af81 488
roborags 18:293c2885af81 489 FPS_Ret = FPS.Enroll_N(Temp_i_1);
roborags 18:293c2885af81 490 if(FPS_Ret != 0)
roborags 18:293c2885af81 491 {
roborags 18:293c2885af81 492 FRDM_UART_Debug.printf("FPS Enroll Failed trying again\r\n");
roborags 18:293c2885af81 493 continue;
roborags 18:293c2885af81 494 }
roborags 18:293c2885af81 495
roborags 18:293c2885af81 496 FPS_Ret = FPS.CmosLed(0);
roborags 18:293c2885af81 497 if(FPS_Ret == -1)
roborags 18:293c2885af81 498 {
roborags 18:293c2885af81 499 FRDM_UART_Debug.printf("FPS Enroll Failed trying again\r\n");
roborags 18:293c2885af81 500 continue;
roborags 18:293c2885af81 501 }
roborags 18:293c2885af81 502
roborags 18:293c2885af81 503 FRDM_UART_Debug.printf("FPS REMOVE finger on Sensor NOW\r\n");
roborags 18:293c2885af81 504 }
roborags 18:293c2885af81 505 }
roborags 18:293c2885af81 506
roborags 18:293c2885af81 507 FPS_Ret = FPS.CheckEnrolled(FPS_Enroll_ID);
roborags 18:293c2885af81 508 if(FPS_Ret == 0)
roborags 18:293c2885af81 509 {
roborags 18:293c2885af81 510 FRDM_UART_Debug.printf("FPS Enroll PASSED\r\n");
roborags 18:293c2885af81 511 goto loop_end;
roborags 18:293c2885af81 512 }
roborags 18:293c2885af81 513 else
roborags 18:293c2885af81 514 {
roborags 18:293c2885af81 515 FRDM_UART_Debug.printf("FPS Enroll FAILED\r\n");
roborags 18:293c2885af81 516 goto loop_end;
roborags 18:293c2885af81 517 }
roborags 18:293c2885af81 518 }
roborags 18:293c2885af81 519 else
roborags 18:293c2885af81 520 {
roborags 18:293c2885af81 521 FRDM_UART_Debug.printf("FPS All ID's are full, swithcing to ID delete mode\r\n");
roborags 18:293c2885af81 522 goto delete_fps_id;
roborags 18:293c2885af81 523 }
roborags 18:293c2885af81 524 break;
roborags 18:293c2885af81 525
roborags 18:293c2885af81 526 case 3:
roborags 18:293c2885af81 527 // Delete ID
roborags 18:293c2885af81 528 delete_fps_id:
roborags 18:293c2885af81 529 FRDM_UART_Debug.printf("FPS DELETE ID, enter option select\r\n1. Delete specific ID \r\n2. Delete All \r\n3. Quit\r\n");
roborags 18:293c2885af81 530 FRDM_UART_Debug.scanf("%d",&Temp_i_1);
roborags 18:293c2885af81 531
roborags 18:293c2885af81 532 switch (Temp_i_1)
roborags 18:293c2885af81 533 {
roborags 18:293c2885af81 534 case 1:
roborags 18:293c2885af81 535 case 2:
roborags 18:293c2885af81 536 for(FPS_Attempt = 3;FPS_Attempt >= 1;FPS_Attempt --)
roborags 18:293c2885af81 537 {
roborags 18:293c2885af81 538 FRDM_UART_Debug.printf("FPS Enter Enroll passoword\r\n");
roborags 18:293c2885af81 539 FRDM_UART_Debug.scanf("%s",&FPS_Enroll_Pass[0]);
roborags 18:293c2885af81 540
roborags 18:293c2885af81 541 if(FPS_Enroll_Pass == FPS_ENROLL_PASS)
roborags 18:293c2885af81 542 {
roborags 18:293c2885af81 543 FRDM_UART_Debug.printf("FPS Wrong Enroll passoword %d attempts left\r\n",FPS_Attempt);
roborags 18:293c2885af81 544 }
roborags 18:293c2885af81 545 else
roborags 18:293c2885af81 546 break;
roborags 18:293c2885af81 547 }
roborags 18:293c2885af81 548
roborags 18:293c2885af81 549 FRDM_UART_Debug.printf("FPS Password Authenticated\r\n");
roborags 18:293c2885af81 550
roborags 18:293c2885af81 551 if(Temp_i_1 == 1)
roborags 18:293c2885af81 552 {
roborags 18:293c2885af81 553 FRDM_UART_Debug.printf("FPS Enter ID to delete\r\n");
roborags 18:293c2885af81 554 FRDM_UART_Debug.scanf("%d",&Temp_i_2);
roborags 18:293c2885af81 555
roborags 18:293c2885af81 556
roborags 18:293c2885af81 557 FPS_Ret = FPS.DeleteID(Temp_i_2);
roborags 18:293c2885af81 558 if(FPS_Ret != 0)
roborags 18:293c2885af81 559 {
roborags 18:293c2885af81 560 FRDM_UART_Debug.printf("FPS Unable to delete ID %d\r\n",Temp_i_2);
roborags 18:293c2885af81 561 break;
roborags 18:293c2885af81 562 }
roborags 18:293c2885af81 563 else
roborags 18:293c2885af81 564 FRDM_UART_Debug.printf("FPS ID %d has been deleted\r\n",Temp_i_2);
roborags 18:293c2885af81 565 }
roborags 18:293c2885af81 566 else if(Temp_i_1 == 2)
roborags 18:293c2885af81 567 {
roborags 18:293c2885af81 568 for(FPS_Enroll_ID = 0; FPS_Enroll_ID <20 ;FPS_Enroll_ID++)
roborags 18:293c2885af81 569 {
roborags 18:293c2885af81 570 FPS_Ret = FPS.DeleteID(FPS_Enroll_ID);
roborags 18:293c2885af81 571 }
roborags 18:293c2885af81 572
roborags 18:293c2885af81 573 for(FPS_Enroll_ID = 0; FPS_Enroll_ID <20 ;FPS_Enroll_ID++)
roborags 18:293c2885af81 574 {
roborags 18:293c2885af81 575 FPS_Ret = FPS.CheckEnrolled(FPS_Enroll_ID);
roborags 18:293c2885af81 576 if(FPS_Ret != 0)
roborags 18:293c2885af81 577 continue;
roborags 18:293c2885af81 578 else
roborags 18:293c2885af81 579 break;
roborags 18:293c2885af81 580 }
roborags 18:293c2885af81 581
roborags 18:293c2885af81 582 if(FPS_Enroll_ID == 20)
roborags 18:293c2885af81 583 {
roborags 18:293c2885af81 584 FRDM_UART_Debug.printf("FPS All ID's deleted\r\n");
roborags 18:293c2885af81 585 }
roborags 18:293c2885af81 586 else
roborags 18:293c2885af81 587 {
roborags 18:293c2885af81 588 FRDM_UART_Debug.printf("FPS Delete ALL failed at ID %d\r\n",FPS_Enroll_ID);
roborags 18:293c2885af81 589 }
roborags 18:293c2885af81 590 }
roborags 18:293c2885af81 591
roborags 18:293c2885af81 592 break;
roborags 18:293c2885af81 593 case 3:
roborags 18:293c2885af81 594 default:
roborags 18:293c2885af81 595 goto loop_end;
roborags 18:293c2885af81 596 break;
roborags 18:293c2885af81 597 }
roborags 18:293c2885af81 598
roborags 18:293c2885af81 599 break;
roborags 18:293c2885af81 600
roborags 18:293c2885af81 601 case 4:
roborags 18:293c2885af81 602 default:
roborags 18:293c2885af81 603 goto loop_end;
roborags 18:293c2885af81 604 }
roborags 18:293c2885af81 605 loop_end:
roborags 18:293c2885af81 606 FRDM_UART_Debug.printf("FPS Loop End reached\r\n");
roborags 18:293c2885af81 607
roborags 18:293c2885af81 608 FPS_Ret = FPS.CmosLed(1);
roborags 18:293c2885af81 609 if(FPS_Ret == -1)
roborags 18:293c2885af81 610 {
roborags 18:293c2885af81 611 FRDM_UART_Debug.printf("FPS LED ON Failed Loop End\r\n");
roborags 18:293c2885af81 612 //continue;
roborags 18:293c2885af81 613 }
roborags 18:293c2885af81 614
roborags 18:293c2885af81 615 }
roborags 18:293c2885af81 616
roborags 18:293c2885af81 617
roborags 14:02ddfa711646 618
roborags 15:67a7cca7ae06 619 void ESP_8266_Init(void)
roborags 14:02ddfa711646 620 {
roborags 15:67a7cca7ae06 621 FRDM_UART_Debug.printf("Initializing and Reset ESP\r\n");
roborags 14:02ddfa711646 622
roborags 15:67a7cca7ae06 623 ESP_8266_UART.Reset(); //RESET ESP
roborags 15:67a7cca7ae06 624 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 400); //receive a response from ESP
roborags 18:293c2885af81 625 //if(FPS_Auth)
roborags 18:293c2885af81 626 //FRDM_UART_Debug.printf(ESP_8266_CMD_Recv); //Print the response onscreen
roborags 14:02ddfa711646 627 wait(2);
roborags 14:02ddfa711646 628
roborags 15:67a7cca7ae06 629 strcpy(ESP_8266_CMD_Send,"AT");
roborags 15:67a7cca7ae06 630 ESP_8266_UART.SendCMD(ESP_8266_CMD_Send);
roborags 18:293c2885af81 631 if(FPS_Auth)
roborags 18:293c2885af81 632 FRDM_UART_Debug.printf(ESP_8266_CMD_Send);
roborags 14:02ddfa711646 633 //wait(2);
roborags 15:67a7cca7ae06 634 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 400);
roborags 18:293c2885af81 635 if(FPS_Auth)
roborags 18:293c2885af81 636 FRDM_UART_Debug.printf(ESP_8266_CMD_Recv);
roborags 14:02ddfa711646 637 wait(0.1);
roborags 14:02ddfa711646 638
roborags 15:67a7cca7ae06 639 strcpy(ESP_8266_CMD_Send,"AT+CWMODE=1");
roborags 15:67a7cca7ae06 640 ESP_8266_UART.SendCMD(ESP_8266_CMD_Send);
roborags 18:293c2885af81 641 if(FPS_Auth)
roborags 18:293c2885af81 642 FRDM_UART_Debug.printf(ESP_8266_CMD_Send);
roborags 14:02ddfa711646 643 wait(2);
roborags 15:67a7cca7ae06 644
roborags 17:690d692b29cb 645
roborags 18:293c2885af81 646 if(!strcmp(ESP_8266_CMD_Recv,"WIFI CONNECTED"))
roborags 15:67a7cca7ae06 647 {
roborags 15:67a7cca7ae06 648 strcpy(ESP_8266_CMD_Send,"AT+CWJAP=\"");
roborags 15:67a7cca7ae06 649 strcat(ESP_8266_CMD_Send,WIFI_SSID);
roborags 15:67a7cca7ae06 650 strcat(ESP_8266_CMD_Send,"\",\"");
roborags 15:67a7cca7ae06 651 strcat(ESP_8266_CMD_Send,WIFI_PASS);
roborags 15:67a7cca7ae06 652 strcat(ESP_8266_CMD_Send,"\"");
roborags 14:02ddfa711646 653
roborags 15:67a7cca7ae06 654 ESP_8266_UART.SendCMD(ESP_8266_CMD_Send);
roborags 18:293c2885af81 655 if(FPS_Auth)
roborags 18:293c2885af81 656 FRDM_UART_Debug.printf(ESP_8266_CMD_Send);
roborags 15:67a7cca7ae06 657 wait(5);
roborags 15:67a7cca7ae06 658 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 400);
roborags 18:293c2885af81 659 if(FPS_Auth)
roborags 18:293c2885af81 660 FRDM_UART_Debug.printf(ESP_8266_CMD_Recv);
roborags 15:67a7cca7ae06 661 }
roborags 18:293c2885af81 662 else
roborags 18:293c2885af81 663 FRDM_UART_Debug.printf("Wifi was preconfigured\r\n");
roborags 15:67a7cca7ae06 664
roborags 15:67a7cca7ae06 665 strcpy(ESP_8266_CMD_Send,"AT+CIPMUX=0");
roborags 15:67a7cca7ae06 666 ESP_8266_UART.SendCMD(ESP_8266_CMD_Send);
roborags 18:293c2885af81 667 if(FPS_Auth)
roborags 18:293c2885af81 668 FRDM_UART_Debug.printf(ESP_8266_CMD_Send);
roborags 14:02ddfa711646 669 //wait(2);
roborags 15:67a7cca7ae06 670 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 400);
roborags 18:293c2885af81 671 if(FPS_Auth)
roborags 18:293c2885af81 672 FRDM_UART_Debug.printf(ESP_8266_CMD_Recv);
roborags 14:02ddfa711646 673
roborags 14:02ddfa711646 674 }
roborags 14:02ddfa711646 675
roborags 15:67a7cca7ae06 676 void ESP_8266_TX_Data(void)
roborags 14:02ddfa711646 677 {
roborags 14:02ddfa711646 678
roborags 14:02ddfa711646 679 //ESP updates the Status of Thingspeak channel//
roborags 14:02ddfa711646 680
roborags 15:67a7cca7ae06 681 strcpy(ESP_8266_CMD_Send,"AT+CIPSTART=");
roborags 15:67a7cca7ae06 682 strcat(ESP_8266_CMD_Send,"\"TCP\",\"");
roborags 15:67a7cca7ae06 683 strcat(ESP_8266_CMD_Send,IP);
roborags 15:67a7cca7ae06 684 strcat(ESP_8266_CMD_Send,"\",80");
roborags 14:02ddfa711646 685
roborags 15:67a7cca7ae06 686 ESP_8266_UART.SendCMD(ESP_8266_CMD_Send);
roborags 18:293c2885af81 687 if(FPS_Auth)
roborags 18:293c2885af81 688 FRDM_UART_Debug.printf("S\r\n%s",ESP_8266_CMD_Send);
roborags 14:02ddfa711646 689 //wait(2);
roborags 15:67a7cca7ae06 690 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 1000);
roborags 18:293c2885af81 691 if(FPS_Auth)
roborags 18:293c2885af81 692 FRDM_UART_Debug.printf("R\r\n%s",ESP_8266_CMD_Recv);
roborags 14:02ddfa711646 693 wait(1);
roborags 14:02ddfa711646 694
roborags 15:67a7cca7ae06 695 /*
roborags 15:67a7cca7ae06 696 float Amm_Out = 0;
roborags 15:67a7cca7ae06 697 float Volt_Out = 0;
roborags 15:67a7cca7ae06 698 float Light_Out = 0;
roborags 15:67a7cca7ae06 699 float Thermo_Out = 0;
roborags 15:67a7cca7ae06 700 float Temp_Out = 0;
roborags 15:67a7cca7ae06 701 float Hum_Out = 0;
roborags 15:67a7cca7ae06 702 int Motion_Out = 0;
roborags 15:67a7cca7ae06 703 */
roborags 15:67a7cca7ae06 704 sprintf(ESP_8266_CMD_Send,"GET https://api.thingspeak.com/update?key=JJAOBK32WOINKT00&field1=%d&field2=%d&field3=%f&field4=%f&field5=%f&field6=%f&field7=%f&field8=%f\r\n"
roborags 15:67a7cca7ae06 705 ,Motion_Out,Finger_Out,Amm_Out,Volt_Out,Light_Out,Thermo_Out,Temp_Out,Hum_Out);
roborags 14:02ddfa711646 706
roborags 14:02ddfa711646 707 int i=0;
roborags 15:67a7cca7ae06 708 for(i=0;ESP_8266_CMD_Send[i]!='\0';i++);
roborags 14:02ddfa711646 709 i++;
roborags 14:02ddfa711646 710 char cmd[255];
roborags 14:02ddfa711646 711
roborags 14:02ddfa711646 712 sprintf(cmd,"AT+CIPSEND=%d",i); //Send Number of open connection and Characters to send
roborags 15:67a7cca7ae06 713 ESP_8266_UART.SendCMD(cmd);
roborags 18:293c2885af81 714 if(FPS_Auth)
roborags 18:293c2885af81 715 FRDM_UART_Debug.printf("S\r\n%s",cmd);
roborags 15:67a7cca7ae06 716 while(i<=20 || ESP_8266_CMD_Recv == ">")
roborags 14:02ddfa711646 717 {
roborags 15:67a7cca7ae06 718 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 1000);
roborags 14:02ddfa711646 719 wait(100);
roborags 14:02ddfa711646 720 i++;
roborags 14:02ddfa711646 721 }
roborags 18:293c2885af81 722 if(FPS_Auth)
roborags 18:293c2885af81 723 FRDM_UART_Debug.printf("R\r\n%s",ESP_8266_CMD_Recv);
roborags 14:02ddfa711646 724
roborags 15:67a7cca7ae06 725 ESP_8266_UART.SendCMD(ESP_8266_CMD_Send); //Post value to thingspeak channel
roborags 18:293c2885af81 726 if(FPS_Auth)
roborags 18:293c2885af81 727 FRDM_UART_Debug.printf("S\r\n%s",ESP_8266_CMD_Send);
roborags 14:02ddfa711646 728
roborags 15:67a7cca7ae06 729 while(i<=20 || ESP_8266_CMD_Recv == "OK")
roborags 14:02ddfa711646 730 {
roborags 15:67a7cca7ae06 731 ESP_8266_UART.RcvReply(ESP_8266_CMD_Recv, 1000);
roborags 14:02ddfa711646 732 wait(100);
roborags 14:02ddfa711646 733 i++;
roborags 14:02ddfa711646 734 }
roborags 18:293c2885af81 735 if(FPS_Auth)
roborags 18:293c2885af81 736 FRDM_UART_Debug.printf("R\r\n%s",ESP_8266_CMD_Recv);
roborags 14:02ddfa711646 737
roborags 14:02ddfa711646 738 }
roborags 14:02ddfa711646 739