nodeMCU client is working
authorMart Lubbers <mart@martlubbers.net>
Tue, 4 Apr 2017 09:11:53 +0000 (11:11 +0200)
committerMart Lubbers <mart@martlubbers.net>
Tue, 4 Apr 2017 09:11:53 +0000 (11:11 +0200)
client/client.c
client/nodemcu/interface.cpp

index 0218fb7..6502fb7 100644 (file)
@@ -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;
index 3ac929c..2df5c1c 100644 (file)
@@ -1,7 +1,25 @@
 #include <Arduino.h>
+#include <ESP8266WiFi.h>
 #include <stdbool.h>
 #include <stdint.h>
 
+#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");
        }
 }