I’m trying to setup a webserver and Blynk together, but I think they’re some how conflicted. I’ve read the post here Blynk and ESP8266WebServer that it will work, but that leads to couple failures…
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleEsp8266.h>
ESP8266WebServer server(80);
char auth[] = "auth";
char ssid[] = "";
char pass[] = "";
IPAddress staticIP(192, 168, 1, 15);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(1, 1, 1, 1);
void handleRoot() {
server.send(200, "text/html", "ok");
}
void connectToWifi() {
WiFi.disconnect();
WiFi.config(staticIP, gateway, subnet);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void startBlynk() {
Blynk.config(auth);
Blynk.begin(auth, ssid, pass);
}
void startServer() {
server.begin();
server.on("/", handleRoot);
}
void setup()
{
Serial.begin(115200);
connectToWifi();
startServer();
startBlynk();
}
BLYNK_WRITE(V0) {
Serial.println("turning on");
}
void loop()
{
if (WiFi.status() != WL_CONNECTED) {
connectToWifi();
}
server.handleClient();
Blynk.run();
}
I think Blynk will have to use the existing wifi, but I’m not sure how. thanks for the help!