ESP8266 (Adafruit Huzzah) disconnects immediately from WiFi, STA disconnect: 203 - esp8266

I have a PM sensor, made for the initiative "sensor community", outside the window, attached to an ESP8266 which connected to a repeater that repeats my home network. Yesterday morning I noticed that suddenly it wasn't publishing the values anymore.
Today I reflashed the board, which is an Adafruit Huzzah with an ESP8266 on board, with the basic example WiFiClientBasic from the ESP82666 library switching on the serial debug of the WiFi.
void setup() {
Serial.begin(115200);
// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
}
The debug yields continuously this error:
[WIFI] Connecting BSSID: SSID: Channel: 6 (-39)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 0 (12)
wifi evt: 1
STA disconnect: 203
reconnect
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 0 (12)
wifi evt: 1
STA disconnect: 203
reconnect
Another ESP8266 board (a LOLIN Wemos) that had the same configuration refuses to connect. Other devices connected to the same network (my 2 laptops, an Android tablet, a Raspberry Pi) don't have any troubles.
The repeater has a DHCP running and has no problem in releasing IP to other devices. Assigning the ESP8266 a static IP, both on the board and/or on the repeater, has no effect.
I'm not a network expert, but those are the main configs of the repeater (a rather old Digicom REW300).
WLAN STATUS Infrastructure Client --- (Connected)
Signal Strenght 54%
Channel-Band 2.4GHz (G+N) channel 6
Rate 13Mbps (MCS1)
Encryption WPA2-PSK
Repeater Status
WLAN STATUS AP --- (Enabled)
Rate auto
Encryption WPA2-PSK
I also looked at the log on the repeater:
Mar 19 16:01:12 DIGICOM-REW300-Z01 user.warn kernel: wlan0-vxd: A wireless client is deauthenticated - "MAC address of the ESP8266"
Mar 19 16:01:13 DIGICOM-REW300-Z01 user.warn kernel: wlan0-vxd: A wireless client is deauthenticated - "MAC address of the ESP8266"
Mar 19 16:01:15 DIGICOM-REW300-Z01 user.warn kernel: wlan0-vxd: A wireless client is deauthenticated - "MAC address of the ESP8266"
I didn't change the settings of the repeater recently, however yesterday morning the ISP changed the main router with a newer one. I think that could be the problem, but anyway the ESP8266 isn't connecting directly to it (it's too far away) but to the repeater which didn't change at all. Moreover: if I take the ESP8266 inside, it can connect to the main router without any troubles. It seems that the combination of new router and old repeater caused the problem, and just only for the ESP8266s. The only thing that changed from the old router is that the new one has only band G+N only, while the old one had B+G+N, I don't think it matters anyway, as it can be connected directly, and the old repeater is B+G+N.
The official docs from Espressif says that error 203 is ASSOC_FAIL, which is a rather generic error.
Further test I did: if the repeater is tethered with my mobile, the ESP8266 connects.
So:
ESP8266 to repeater to WAN (broken)
ESP8266 to WAN (OK)
ESP8266 to repeater to Mobile Phone to WAN (OK)

Maybe add these lines can help...
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
Here an example with reconection and status connection

Related

iOS somehow reduce my network speed in Wifi connection to my Camera device in AP

I'm developing iOS Application for communication with manufactured Camera via WiFi using custom API.
I have camera device in Wifi mode AP.
I'm connecting to that device via Wifi using NEConnection to specific port. TCP protocol.
We have 2 ports, one for messages other for data transferring.
Then using API. I'm building specific message, converting them to Data and sending to Camera device. I can receive data or message data from Camera as well.
I need to download video file with for example 100MB. And it take a lot of time.
Issue is: While receiving data from device we have speed ± 160 KB/s, but android with the same configurations has 2MB/s.
Why it happens, does Apple makes some speed limitation? Could it be related to Wifi as it doesn't has internet connection?
NWConnection constructor:
static func createConnection(host hostAddress: String, port portInt: UInt16) -> NWConnection {
let ipv4: IPv4Address = .init(hostAddress) ?? .any
let host: NWEndpoint.Host = .ipv4(ipv4)
let port: NWEndpoint.Port = .init(rawValue: portInt) ?? .any
let tcpOptions: NWProtocolTCP.Options = NWProtocolTCP.Options.init()
return .init(host: host, port: port, using: .init(tls: nil, tcp: tcpOptions))
}

ESP8266 cannot reconnect to last saved WiFi network

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");
}

ESP8266: Wifi gets connected, but no internet access

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/

iOS & Safari 11 WebRTC does not gather STUN/TURN Trickle ICE Candidates

My web application is failing to gather WebRTC relay ICE candidates via a CoTURN server when using Safari 11 on iOS 11 (iPhone 5s & iPhone 7) or desktop. The web application (which establishes a one-way audio only WebRTC peer connection) works fine between the real browsers (Chrome and Firefox) either direct or via CoTURN relay, and I normally get 6-15 ICE candidates on these browsers.
I have a (frankly, unnecessary) call to getUserMedia on the receiving side, which allows host ICE candidates to be produced by Safari. (Note... the user must approve audio and/or video access before Safari will provide host Ice Candidates, even if on a receiving-only end. I'm past that hurdle, but just so you won't hit it too... This is out of "privacy" concerns.). Before I added the allow getUserMedia, I received no ICE. Now I receive two candidates. One with a private IPv4 and another with an IPv6. This is enough to get the app working properly when on the same machine or local network. So I'm pretty confident with other parts of the application code. I am not sure if my problem is with the application code or the CoTURN server.
Example of the ICE candidates received:
{"candidate":{"candidate":"candidate:622522263 1 udp 2113937151 172.27.0.65 56182 typ host generation 0 ufrag r23H network-cost 50","sdpMid":"audio","sdpMLineIndex":0,"usernameFragment":"r23H"}}
I pretty sure the RTCIceServer Dictionary for my RTCPeerConnection is inline with the following standards:
https://w3c.github.io/webrtc-pc/webrtc.html
https://www.rfc-editor.org/rfc/rfc7064
https://www.rfc-editor.org/rfc/rfc7065
And I've tried multiple variations of parameters:
// For Example:
var RPCconfig = {
iceServers: [{
urls: "turn:Example.live",
username: "un",
credential: "pw"
}]
};
// Or:
var RPCconfig = {
iceServers: [{
urls: "turns:Example.live",
username: "un",
credential: "pw",
credentialType: "password"
}, {
urls: "stun:Example.live"
}]
};
// And even more desperate attempts...
var RPCconfig = {
iceServers: [{
urls: "turn:Example.live?transport=tcp",
username: "un",
credential: "pw",
credentialType: "password"
}]
};
Here's an example of the signaling process log for an idea of what is going on. This is from the receiving side, which is Safari 11. The other browser was Chrome (compare 6 vs 2 ICE candidates). The state change refers to oniceconnectionstatechange.
SDP Offer received.
Sending signal SDP
Sending signal IceCandidate
Sending signal IceCandidate
ICE Candidate Received
4:08:25 AM State Change -> checking
ICE Candidate Received
ICE Candidate Received
ICE Candidate Received
ICE Candidate Received
ICE Candidate Received
4:08:40 AM State Change -> failed
CoTURN is configured quite liberally in terms of accepting every possible transport method as far as I am aware. It works well for providing ICE Candidates and as a relay for the other browsers.
Any direction would be greatly appreciated. Even if it is just a sample RTCIceServer Dictionary code that works or a proven TURN server to try.

pjsip call :hangup videocall will block thread when network disconnected

I have a chat application developed by oc.I'm currently using pjsip library to register to a SIP server using PJSIP.I use pjsua_call_make_call to make videoCall,and use pjsua_call_hangup to hangup call.when network is reachable,everything is ok .This is a problem when network disconnected. Below are steps to reproduce(audiocall is ok and i have search similar problems but no results) :
make videoCall to other,other answer the call to change videoCall state to confirmed
i disconnected network
i hangup videocall
then issue appear:thread will be blocked,hangup failure
below are log:
14:21:35.527 tsx0x1042f82a8 ....Failed to send Request msg BYE/cseq=2 (tdta0x1042c2ea8)! err=120051 (Network is unreachable)
14:21:35.527 tsx0x1042f82a8 ....State changed from Null to Terminated, event=TRANSPORT_ERROR
14:21:35.527 dlg0x10411a6a8 .....Transaction tsx0x1042f82a8 state changed to Terminated
14:21:35.527 Pjsua_call.c .......im pjsua_call_get_info get Date Wed, 09 Aug 2017 06:21:06 GMT
14:21:35.527 Pjsua_call.c .......im pjsua_call_get_info get call_info 1
14:21:35.537 strm0x1042c7a28 !Starting silence
14:21:35.569 pjsua_media.c !.......Call 0: deinitializing media..
14:21:35.569 strm0x1042c7a28 .........JB summary:size=0/eff=0 prefetch=0 level=10 delay (min/max/avg/dev)=360/500/425/45 ms burst (min/max/avg/dev)=1/11/2/2 frames lost=25 discard=29 empty=218
14:21:35.569 pjsua_media.c .........Media stream call00:0 is destroyed
14:21:35.569 pjsua_vid.c .........Stopping video stream..
14:21:35.609 darwin_dev.m ..........Stopping Darwin video stream
14:21:35.663 pjsua_vid.c ..........Window 1: destroying..
14:21:35.663 vid_port.c ...........Closing Front Camera..

Resources