I'm using WifiManager library to manually add user's network on configuration portal. Already it works fine, but every time I power off and power on again, it does not connect to network I have established previous. To connect I have to pin out the 'Vcc' of ESP8266 and pin in again and then again connect with ESP8266 network and go to configure portal.
For now I have two lines in code with 'WifiManager';
Good news is that connects to Wifi by configurationPortal.
ESP8266WebServer server; //server variable
void setup() {
initializePin(); //call function
Serial.begin(74880);
delay(500);
//Connect to network
WiFiManager wifiManager;
wifiManager.autoConnect("ESP8266","password");
Serial.println("Connected.");
if (!MDNS.begin("esp8266")) { Serial.println("Error setting up MDNS responder!"); }
else { Serial.println("mDNS responder started"); }
serverSection();
server.begin();
Serial.println("Server started");
}
I need to connect to previous established network,
Also it would be fine to run Configuration Portal if there wont be connection to that network ( for example if device would be transfer to other place)
Your code is supposed to connect to the internet. What happens usually when you use auto connect and it fails is that WL_IDLE_STATUS occurs. Read more about it here: https://www.arduino.cc/en/Reference/WiFiStatus . What I would do is to check if I got that status then I would try to reconnect to the wifi with a delay of 2 seconds. Here is an example:
if (WiFi.status() == WL_IDLE_STATUS) {
delay(2000);
WiFi.begin("yourssid", "password");
}
Related
I am trying to connect my ESP8266 NodeMCU to my Mobile Hotspot Wifi
When I try to connect to the ESP Wifi using laptop, It says Wifi Connected, no Internet access.
Which means, The Wifi_SSID and Password are fetched by ESP correctly.
Why is the ESP not able to connect to the Internet?
I have used Arduino IDE for uploading code to ESP8266.
I have uploaded the below code to the ESP8266.
#include <FirebaseArduino.h>
#include <ESP8266WiFi.h>
// Set these to run example.
#define WIFI_SSID "OnePlus3"
#define WIFI_PASSWORD ""
#define FIREBASE_DB_URL "https://my_db_url.firebaseio.com/"
#define FIREBASE_DB_SECRET_KEY "fakezaSyDsdadasddwGClaAy8ltYgywwo6i_VzXgY"
void setup() {
Serial.begin(115200);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Firebase.begin(FIREBASE_DB_URL, FIREBASE_DB_SECRET_KEY);
Firebase.stream("/automation");
}
void loop() {
if (Firebase.failed()) {
Serial.println("streaming error");
Serial.println(Firebase.error());
}
if (Firebase.available()) {
FirebaseObject event = Firebase.readEvent();
String eventType = event.getString("type");
eventType.toLowerCase();
Serial.print(eventType);
if (eventType == "put") {
String path = event.getString("path");
String data = event.getString("data");
if (path.equals("/fan/value")) {
if (data.equals("off")) {
digitalWrite(D1, HIGH);
} else {
digitalWrite(D1, LOW);
}
} else if (path.equals("/light/value")) {
if (data.equals("off")) {
digitalWrite(D2, HIGH);
} else {
digitalWrite(D2, LOW);
}
}
}
}
}
Troubleshooting ESP8266 not connecting to WiFi
Failure to connect to the WiFi network can be caused by some factors. Among them I highlight:
1 - The ESP8266 has a particularity of the initial state of its GPIOs during an initialization. As the intention is to make a connection to the Internet, I suggest that you leave the ESP8266 only with the power and communication connections. If you have a NodeMCU you can use only the USB cable.
2 - Wrong filling in of the access data of the router will cause an error in the connection. Please note that you have to put in your code the WLAN SSID and WLAN PASS information, which are, respectively, the name and password of your network. It is worth remembering that the capture of these characters is case sensitive.
3 - If your router is not connected to the Internet, then you will have feedback via the serial monitor of your local IP, but you will not have confirmation of access with the Google server. Test it with your smartphone or computer and check if everything is fine with your Internet connection.
4 - It is difficult, but I have already seen incompatibility with the internet provider. To solve, test on different networks. I suggest that we carry out tests with your smartphone functioning as a WiFi router. You can even check the connected devices quickly and easily.
You can learn more about it in this link (Eduardo Castro) in Brazilian Portuguese:
https://www.filipeflop.com/blog/como-conectar-o-esp8266-a-internet/
I am working on an iOS app which has a requirement to automatically connect to a WiFi network. We had requested for a NEHotspotHelper extension from Apple which is approved.
Now I am trying to auto connect to the WiFi network around. But the call to method NEHotspotHelper.register never returns. I have added the entitlement com.apple.developer.networking.HotspotHelper in the entitlement file of the app and am also using a newly created provisioning profile with the said entitlement enabled. Trying to get it work from last week. Looks like a small thing which I am finding difficult to catch. Please help.
Below is my code
if let strWiFi = UserDefaults.standard.value(forKey:"WiFiSSID") as? String {
let queue = DispatchQueue(label: "com.mycompany.myapp")
NEHotspotHelper.register(options: nil, queue: queue,
handler: {(_ cmd: NEHotspotHelperCommand) -> Void in
if cmd.commandType == .evaluate || cmd.commandType == .filterScanList {
var hotspot:NEHotspotNetwork?
for network: NEHotspotNetwork in cmd.networkList! {
print("network name:\(network.ssid)")
if (network.ssid == strWiFi) {
network.setConfidence(.high)
let strPassword = UserDefaults.standard.value(forKey:"WiFiPassword") as? String
network.setPassword(strPassword!)
hotspot = network
}
}
let response = cmd.createResponse(.success)
if(hotspot != nil) {
response.setNetwork(hotspot!)
}
response.deliver()
}
})
Any help is highly appreciated!
EDIT: Now when I tried to disconnect and then reconnecting back to the WiFi then it registration succeeds but returns only the details of currently connected network. I need the details of all WiFi networks around.
Is need to enter in Settings -> Wi-fi, the helper only execute if enter in the screen, I tried too make auto connect, but the user need to select the network to connect in the first time.
If the user select to connect network once, the next time may auto connect, because may enter in command Maintain.
See more: https://forums.developer.apple.com/message/138756#138756
I am trying to connect a dvr using boost asio library in ios. The application works fine in emulator with in ipv4 network. But when I submit the application on Appstore apple rejected the application as it's not work on ipv6 network. And I can see in the apple site that application should support ipv6 network. https://developer.apple.com/news/?id=05042016a
So I think the problem comes at the section where I am trying to connect to DVR using boost library, where the ip address of the DVR is pulled from DB(hard-coded) and below is the relevant part of the code.
boost::asio::io_service io_service_;
tcp::resolver::iterator endpoint_iter_;
tcp::resolver resolver_; //to healp resolving hostname and ip
stringstream strstream;//create a stringstream
strstream << port;//add number to the stream
endpoint_iter_ = resolver_.resolve(tcp::resolver::query(ip.c_str(),strstream.str()));
start_connect(endpoint_iter_);
// Start the deadline actor. You will note that we're not setting any
// particular deadline here. Instead, the connect and input actors will
// update the deadline prior to each asynchronous operation.
deadline_timer_.async_wait(boost::bind(&dvr_obj::check_deadline, this));
//starting thread for dvr connection
io_service_.reset();
thread_ = new boost::thread(boost::bind(&boost::asio::io_service::run, &io_service_));
start_connect method
void start_connect(tcp::resolver::iterator endpoint_iter)
{
try
{
if (endpoint_iter != tcp::resolver::iterator())
{
drill_debug_info("trying to connect %s \n",name.c_str());
// Set a deadline for the connect operation.
deadline_timer_.expires_from_now(boost::posix_time::seconds(10));
// Start the asynchronous connect operation.
socket_.async_connect(endpoint_iter->endpoint(),
boost::bind(&dvr_obj::handle_connect,
this, _1, endpoint_iter));
}
else
{
// There are no more endpoints to try. Shut down the client.
connectivity = false;
}
} catch (int e) {
connectivity = false;
}
}
So I am confused how to change above code to work on IPV6 network. Could not find any solution in Internet.
You can iterate through the endpoints to find an IPv6 endpoint using the code below:
endpoint_iter_ = resolver_.resolve(tcp::resolver::query(ip.c_str(),strstream.str()));
while (endpoint_iter_ != tcp::resolver::iterator())
{
if (endpoint_iter_->endpoint().protocol() == tcp::v6())
break;
++endpoint_iter_;
}
if (endpoint_iter_ != tcp::resolver::iterator())
{
start_connect(endpoint_iter_);
...
}
else
std::cerr << "IPv6 host not found" << std::endl;
I'm running SocketIO-Client-Swift in order to open WebSockets and communicate with a server. However the problem I'm having is that I want to connect to the socket and then connect to the server with an emit.
SocketIOManager.sharedInstance.connectToSocket()
SocketIOManager.sharedInstance.connectToServer(self.myUsername)
And those point to functions here:
func connectToSocket() {
addHandlers()
socket.joinNamespace("/chat")
socket.connect()
}
func addHandlers() {
self.socket.on("connectUser") { data in
print("socket connected")
}
}
func connectToServer(username: String) {
socket.emit("connectUser", username)
}
Even after registering the handle, the emit is being called before the socket is properly connected. The connect works fine after the connect has been established as I can properly send messages and get feedback after my Log shows a connection.
You need to wait for the client to receive the connect event. That will signal that it is now connected and you can safely send initial data on the connection from that event handler.
I am using a Netty server in linux with one netty client in Android. (Netty 4.0.23).
It works perfect most of the time. However, sometimes, my client is not able to connect to server.
The ChannelFuture received when trying to connect tells me that connection is done but not success (with cause not null) so it is completed with failure.
About the failure I received it is a java.net.socketException - EHOSTUNREACH error (No route to host).
I am quite sure that the problem is not in server.
Important:
I always run the server and the client in the same lan wifi network
with local ip addresses.
I have tested it in two different wifi
networks. In one of them, the reported error occurs rarely and in the
other occurs quite often.
CONNECT_TIMEOUT_MILLIS is configured with enough time in both contexts
I attach the way I do the connection from client:
.............
final ChannelFuture futureConnection = bootstrap.connect(HOST, PORT);
futureConnection.awaitUninterruptibly();
if (futureConnection.isDone()){
if (futureConnection.isCancelled()) {
// log error
}
else if (futureConnection.isDone() && futureConnection.isSuccess()){
// do something
}
else if (futureConnection.isDone() && (futureConnection.cause() != null)) {
// log error THIS IS THE ERROR REPORTED
}
else {
// log error
}
}
............