Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 6:9f3f0db71230, committed 2020-04-21
- Comitter:
- star297
- Date:
- Tue Apr 21 09:31:19 2020 +0000
- Parent:
- 5:efcfa9e61907
- Child:
- 7:26dab90b464f
- Commit message:
- code tidy
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 20 23:10:10 2020 +0000
+++ b/main.cpp Tue Apr 21 09:31:19 2020 +0000
@@ -1,12 +1,13 @@
#include "mbed.h"
-// LPC1768
+// LPC1768 ESP8266 works up to 460800 baud
//Serial ports to be used
Serial pc(USBTX,USBRX);//TO BE used for debug info
Serial esp(p13,p14);//TX,RX TO BE CONNECTED TO ESP
Serial esp2(p13,p14);//TX,RX TO BE CONNECTED TO ESP
+int espbaud = 115200;
DigitalOut espreset(p25,1);
//Connections to relay
//relay works at logic LOW
@@ -24,12 +25,13 @@
//Analog Input
AnalogIn tempSensor(p20);
-//F401
+//F401 ESP8266 works up to 460800 baud
/*
//Serial ports to be used
Serial pc(USBTX,USBRX);//TO BE used for debug info
Serial esp(D8,D2);//TX,RX TO BE CONNECTED TO ESP
Serial esp2(D8,D2);//TX,RX TO BE CONNECTED TO ESP
+int espbaud = 115200;
//Connections to relay
//relay works at logic LOW
DigitalOut digital_out_1(D3,1);// High on initialization
@@ -47,9 +49,8 @@
AnalogIn tempSensor(A0);
*/
-char ssid[32] = "ssid"; // enter your router ssid inside the quotes
-char pwd[32] = "password"; // enter your router password inside the quotes
-
+char ssid[32] = "Molino Metz"; // enter your router ssid inside the quotes
+char pwd[32] = "36693557"; // enter your router password inside the quotes
#define BUFFER_SIZE 3000
#define REQ_LINE_BUFF_SIZE 100
@@ -141,7 +142,7 @@
//configure baud rate for UART
pc.baud(115200);
- esp.baud(115200);
+ esp.baud(espbaud);
esp2.attach(&espRxInterrupt,Serial::RxIrq);
@@ -185,10 +186,14 @@
pc.printf("Connected to Wifi\n");
__disable_irq();
esp.printf("AT+CIFSR\r\n");//check obtained IP
- esp.scanf("+CIFSR:STAIP,\"%[^\"]",&serverIp);
+ esp.scanf("+CIFSR:STAIP,\"%15[^\"]",serverIp);
__enable_irq();
while(readEspResponse()!=OK);
}
+ if(responseFromEsp==FAIL){
+ pc.printf("Can't connect to Wifi\n");
+ while(1);
+ }
pc.printf("Server IP is %s\n",serverIp);
@@ -515,20 +520,20 @@
{
analog_out_1=atof(value)/12.0;
char responsePacket[100];
- sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0);
+ sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0f);
sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
}
}
else if(strcmp(request,get_analog_outputs_status)==0)
{
char responsePacket[100];
- sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0);
+ sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0f);
sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
}
else if(strcmp(request,get_analog_inputs_status)==0)
{
char responsePacket[100];
- sprintf(responsePacket,"%s%.2f",textPlainHeader,((tempSensor*3.3)-0.500)*100.0);
+ sprintf(responsePacket,"%s%.2f",textPlainHeader,((tempSensor*3.3f)-0.500f)*100.0f);
sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
}
else