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.
Dependencies: mbed MbedJSONValue mbed-rtos 4DGL-uLCD-SE ESP8266NodeMCUInterface
Revision 12:513a0fd7c426, committed 2019-05-24
- Comitter:
- alexhrao
- Date:
- Fri May 24 23:36:32 2019 +0000
- Parent:
- 11:643f66b447b8
- Child:
- 13:65946a58123e
- Commit message:
- Add demo for new node support
Changed in this revision
| ESP8266NodeMCUInterface.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266NodeMCUInterface.lib Fri May 24 23:19:29 2019 +0000 +++ b/ESP8266NodeMCUInterface.lib Fri May 24 23:36:32 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/alexhrao/code/ESP8266NodeMCUInterface/#a5c7a72aa707 +https://os.mbed.com/users/alexhrao/code/ESP8266NodeMCUInterface/#4224de23da9e
--- a/main.cpp Fri May 24 23:19:29 2019 +0000
+++ b/main.cpp Fri May 24 23:36:32 2019 +0000
@@ -1,5 +1,5 @@
// Change below to 1 to compile for the new node
-#define ESP8226_NEW_NODE 0
+#define ESP8226_NEW_NODE 1
#include "mbed.h"
#include "uLCD_4DGL.h"
#include "ESP8266Interface.h"
@@ -10,6 +10,12 @@
#define BUF_SIZE 4096
+#if ESP8226_NEW_NODE == 0
+#define ESP8226_BAUD_RATE 9600
+#else
+#define ESP8226_BAUD_RATE 115200
+#endif
+
// We need this for being able to reset the MBED (similar to watch dogs)
extern "C" void mbed_reset();
@@ -28,7 +34,7 @@
DigitalOut err_led(LED1);
// WiFi
-ESP8266Interface wifi(p13, p14, p15, 9600, 10000);
+ESP8266Interface wifi(p13, p14, p15, ESP8226_BAUD_RATE, 10000);
// Time
Thread time_thread;
@@ -396,13 +402,20 @@
// Get the Time
TCPSocketConnection time_tcp;
+ #if ESP8226_NEW_NODE == 1
+ time_tcp.connect("www.google.com", 443);
+ #else
time_tcp.connect("api.timezonedb.com", 80);
-
+ #endif
sprintf(cmd,
+ #if ESP8226_NEW_NODE == 1
+ "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n");
+ #else
"GET /v2.1/get-time-zone?key=%s&format=json&by=position&lat=%0.4f&lng=%0.4f HTTP/1.1\r\nHost: api.timezonedb.com\r\n\r\n",
time_api_key,
latitude,
longitude);
+ #endif
time_tcp.send_all(cmd, strlen(cmd));
@@ -443,6 +456,7 @@
}
}
buffer[footer_ind + 1] = '\0';
+ #if ESP8226_NEW_NODE == 0
parser = new MbedJSONValue();
parse(*parser, buffer + header_ind);
@@ -450,6 +464,9 @@
// Add 3 so that we make up for TCP request - empirically...
set_time((*parser)["timestamp"].get<int>() + 5 + 3);
delete(parser);
+ #else
+ set_time(100000);
+ #endif
lcd_lock.lock();
uLCD.cls();
lcd_lock.unlock();
