From 39da74c72f4df302273fa2da5d23f3cc6e05d9fa Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 4 Apr 2017 11:11:53 +0200 Subject: [PATCH] nodeMCU client is working --- client/client.c | 4 +++ client/nodemcu/interface.cpp | 52 ++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/client/client.c b/client/client.c index 0218fb7..6502fb7 100644 --- a/client/client.c +++ b/client/client.c @@ -63,6 +63,8 @@ void read_message(void) default: debug("Unknown message: %X", c); } + } else { +// debug("No input"); } } @@ -73,7 +75,9 @@ void loop(void) if(getmillis()-loopmillis < LOOPDELAY){ return; } + loopmillis = getmillis(); #endif + debug("Loop"); int ct; long cyclestart; diff --git a/client/nodemcu/interface.cpp b/client/nodemcu/interface.cpp index 3ac929c..2df5c1c 100644 --- a/client/nodemcu/interface.cpp +++ b/client/nodemcu/interface.cpp @@ -1,7 +1,25 @@ #include +#include #include #include +#define SSID "ASUS_NDL" +#define WPA2KEY "RT-AC66U" +#define PORT 8123 + +extern "C" unsigned long getmillis(void); +extern "C" void pdie(char *, ...); +extern "C" void die(char *, ...); +extern "C" void debug(char *, ...); +extern "C" void real_setup(void); +extern "C" void write_byte(uint8_t); +extern "C" uint8_t read_byte(void); +extern "C" bool input_available(void); +extern "C" void msdelay(unsigned long); + +WiFiServer server(PORT); +WiFiClient client; + unsigned long getmillis(void) { return millis(); @@ -14,23 +32,47 @@ void msdelay(unsigned long ms) bool input_available(void) { - return Serial.available(); + return client.available(); } uint8_t read_byte(void) { - return Serial.read(); + return client.read(); } void write_byte(uint8_t b) { - Serial.write(b); + client.write(b); } void real_setup(void) { Serial.begin(115200); - Serial.println("Hello world!"); + Serial.print("Connecting to "); + Serial.println(SSID); + WiFi.begin(SSID, WPA2KEY); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + server.begin(); + Serial.print("Server started on port: "); + Serial.println(PORT); + + Serial.print("Waiting for a client to connect."); + while(true){ + client = server.available(); + if(client){ + break; + } + } + Serial.print("Client connected: "); + Serial.println(client.connected()); + Serial.println(""); } void debug(char *fmt, ...) @@ -42,7 +84,7 @@ void die(char *fmt, ...) { Serial.print(fmt); while(1){ - msdelay(100); + msdelay(1000); Serial.print("die"); } } -- 2.20.1