I am trying to use a local server running on a Raspberry Pi 3 connected to an AP which is a D-Link ACI 1200 router (DIR-842). This local server will be used in a high school robotics class to teach IoT concepts with NodeMCU ESP8266 12-E modules. Instead of using the Blynk server I would like to set up the local server to increase speed of the applications and give the students enough credits to build more complex apps. I had this local server up and running last fall at home but I am struggling to connect the ESP to it. I should also say that I am a high school teacher, not a programmer or engineer. My networking experience in skills are improving but lacking.
I am able to get the wifi client sketch below to work:
This sketch establishes a TCP connection to a "quote of the day" service.
It sends a "hello" message, and then prints received data.
*/
#include <ESP8266WiFi.h>
#ifndef STASSID
#define STASSID "myssid"
#define STAPSK "mypass"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "djxmmx.net";
const uint16_t port = 17;
void setup() {
Serial.begin(115200);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
// This will send a string to the server
Serial.println("sending data to server");
if (client.connected()) {
client.println("hello from ESP8266");
}
// wait for data to be available
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
delay(60000);
return;
}
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("receiving from remote server");
// not testing 'client.connected()' since we do not need to send data here
while (client.available()) {
char ch = static_cast<char>(client.read());
Serial.print(ch);
}
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
delay(300000); // execute once every 5 minutes, don't flood remote service
}
However, when I upload this sketch with an auth token for a simple app on Blynk I can run it on the Blynk server but not on my local server. Here is that sketch:
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "1f48...ca49";
// WiFi credentials.
char ssid[] = "myssid";
char pass[] = "mypass";
int pinV0;
int redLED = 2;
int count = 0;
void setup() {
Blynk.begin(auth, ssid, pass);
pinMode (redLED, OUTPUT);
digitalWrite (redLED, HIGH);
delay (1000);
Serial.begin (9600);
}
void loop() {
Serial.print("test ");
Serial.println(count);
delay(2000);
count++;
Blynk.run();
if (pinV0 == 1){
digitalWrite(redLED, HIGH);
}
else {
digitalWrite(redLED, LOW);
}
}
BLYNK_WRITE(V0){
pinV0 = param.asInt(); // assigns incoming value button to pinV0 variable
}
My Blynk local server is running and is connected to the internet. What are some troubleshooting steps to take?