Hi,
I have a simple code connecting to my local wifi using the ESP8266 and the arduino mega board.
currently the system connects to the wifi and gets an ip (that I can not change ) 197.7.1.150 this is out of my router subnet which is 192.168.1.1-255
I am using the library ESP8266_Lib.h and BlynkSimpleShieldEsp8266.h
is it possible to set the IP address I want or have my router give it one using DHCP?
if someone has an idea what else could be wrong I would be happy to hear
the code is below
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "###############";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "S#####";
char pass[] = "#########";
char server[] = "188.166.206.43";
int port = 80;
byte arduino_mac[] = { 0x0c, 0x13, 0x00, 0x03, 0x93, 0x02 };
char device_ip[] = "192.168. 0.80";
char dns_ip[] = "8.8.8.8";
char gateway_ip[] = "192.168.0.1";
char subnet_mask[] = "255.255.255.0";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial3
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
// Attach virtual serial terminal to Virtual Pin V0
WidgetTerminal terminal(V0);
// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V0)
{
// if you type "Marco" into Terminal Widget - it will respond: "Polo:"
if (String("Marco") == param.asStr()) {
terminal.println("You said: 'Marco'") ;
terminal.println("I said: 'Polo'") ;
} else {
// Send it back
terminal.print("You said:");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
}
// Ensure everything is sent
terminal.flush();
}
void setup()
{
// Debug console
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
Serial.write("----------debug 1 -----");
//wifi.setStationIp(String ip,String gateway,String netmask,uint8_t pattern)
wifi.setStationIp(device_ip,gateway_ip,subnet_mask,3);
delay(3000);
Serial.write("----------debug 2 -----");
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
//Serial.print("FW Version:");
//Serial.println(wifi.getVersion().c_str());
//Serial.print("Status:[");
//Serial.print(wifi.getIPStatus().c_str());
//Serial.println("]");
Serial.print("KICK: ");
Serial.println(wifi.kick());
//Serial.println("getAPList");
//Serial.println(wifi.getAPList().c_str());
//Serial.println("getIPStatus");
//Serial.println(wifi.getIPStatus().c_str());
Blynk.begin(auth,wifi,ssid,pass,server,port);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(188,166,206,43), 8080);
Serial.write("----------debug 3 -----");
// This will print Blynk Software version to the Terminal Widget when
// your hardware gets connected to Blynk Server
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.println(F("-------------"));
terminal.println(F("Type 'Marco' and get a reply, or type"));
terminal.println(F("anything else and get it printed back."));
terminal.flush();
}
void loop()
{
Serial.println("ESP8266 board info:");
Serial.write("---------------");
Blynk.run();
}