Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DEBUG - ESP8266 wifi doesn't connect / visual studio 2017 (Read 4832 times)
Joao Tavares
Newbies
*
Offline


Posts: 9
Joined: Nov 24th, 2017
DEBUG - ESP8266 wifi doesn't connect / visual studio 2017
Nov 27th, 2017 at 9:52am
Print Post  
Good morning
I am quite new to Visual Micro but I am having a problem that has already been reported last April:
I am using ESP8266 (NodeMcu) and when I load the project in Debug the ESP8266 is unable to connect to the WIFI network. If I load the project in Release mode the ESP8266 connects to the WIFI network without problems. But if I try to put a delay of 3000 in the begin of the setup in Release mode then the ESP8266 is again enable to connect to the network. I am using the normal wifi connection to my home router and version 1.1711.19 of Visual Micro. From the answer given in April to someone with the same problem it was supposed that the problem should already be solved in the actual version. Thank you in advance. Best regards   
« Last Edit: Nov 28th, 2017 at 6:15pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ESP8266 wifi doesn't connect / visual studio 2017
Reply #1 - Nov 27th, 2017 at 9:23pm
Print Post  
Hi,

Let us just stick with release mode until we understand the issue.

I can tell you that normally you can not use a delay on the esp9266 until after wifi connect. It prevents a wifi connect unless the conect is attempted a second time. 

Does this help?
  
Back to top
IP Logged
 
Joao Tavares
Newbies
*
Offline


Posts: 9
Joined: Nov 24th, 2017
Re: ESP8266 wifi doesn't connect / visual studio 2017
Reply #2 - Nov 28th, 2017 at 9:09am
Print Post  
Good morning

Thank you for your answer but the problem is not that I want a delay in the setup. The problem is that without any delay made by me when I compile using debug the ESP8266 is not connecting to the WIFI. I only spoke about the delay because in April some one from Visual Micro asked to try to put a delay in the setup to see if in the Release mode the problem would appear, and it dose.

Best regards

Joao
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: DEBUG - ESP8266 wifi doesn't connect / visual studio 2017
Reply #3 - Nov 28th, 2017 at 6:14pm
Print Post  
I see thanks. The esp8266 is a strange unit before wifi connects.

Have you set the vMicro>Debugger options to use Serial?

Confirm no breakpoints in setup() ?

Can you try this code and tell me if it connects when debug is enabled?

Thanks

Code
Select All
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
bool ota_started;

const char* ssid = "YOUR_ROUTER_SSID";
const char* password = "YOUR_ROUTER_WIFI_PASSWORD";
void setup()
{
 Serial.begin(115200);
 ConnectToWiFi();
 StartOTAIfRequired();
 PrintWifiStatus();
 Serial.println("Connected to wifi");
}
void loop()
{
 //Serial.println("Hello world");
 HandleOTA();
}

void ConnectToWiFi()
{
 Serial.begin(115200);
 Serial.println("Booting");
 WiFi.mode(WIFI_STA);
 Serial.println("Mode set");
 WiFi.begin(ssid, password);
 Serial.println("Begin complete");
}
void HandleOTA()
{
 StartOTAIfRequired();
 ArduinoOTA.handle();
}
void StartOTAIfRequired()
{
 if (ota_started)
 return;
 // Port defaults to 8266
 // ArduinoOTA.setPort(8266);
 // Hostname defaults to esp8266-[ChipID]
 //if (ArduinoOTA.getHostname() && ArduinoOTA.getHostname().length())

 // No authentication by default
 ArduinoOTA.setPassword((const char *)"123");
 ArduinoOTA.onStart([]() {
 Serial.println("OTA Start");
 });
 ArduinoOTA.onEnd([]() {
 Serial.println("\nOTA End");
 });
 ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
 Serial.printf("Progress: %u%%\r\n", (progress / (total / 100)));
 });
 ArduinoOTA.onError([](ota_error_t error) {
 Serial.printf("Error[%u]: ", error);
 if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
 else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
 else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
 else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
 else if (error == OTA_END_ERROR) Serial.println("End Failed");
 });
 ArduinoOTA.begin();
 ota_started = true;
 delay(500);

}
void PrintWifiStatus()
{
 // print the SSID of the network you're attached to:
 Serial.print("SSID: ");
 Serial.println(WiFi.SSID());
 //using dhcp? wait for ip or ip not set!
 if (WiFi.localIP()[0] == 0)
 {
 Serial.println("DHCP: Waiting for IP Address ...");
 while (WiFi.localIP()[0] == 0)
 {
 yield();
 }
 }
 // print your WiFi shield's IP address:
 IPAddress ip = WiFi.localIP();
 Serial.print("IP Address: ");
 Serial.println(ip);
 //Serial.println(WiFi.status());
}
  

« Last Edit: Nov 28th, 2017 at 6:15pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Joao Tavares
Newbies
*
Offline


Posts: 9
Joined: Nov 24th, 2017
Re: DEBUG - ESP8266 wifi doesn't connect / visual studio 2017
Reply #4 - Nov 29th, 2017 at 5:13pm
Print Post  
Thank you for your answer.
Your code works well and the ESP8266 connects to the nework and dose my code now.
I understood, from your text and code, that I should start to connect to the network before doing anything else. I Put the star of the WiFi in my code just at the beginning of the setup, and not after some initializations I was doing and the problem was solved. 

Thank very much for your help.

Best regards

Joao
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: DEBUG - ESP8266 wifi doesn't connect / visual studio 2017
Reply #5 - Dec 1st, 2017 at 12:12am
Print Post  
Excellent thanks for letting me know
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint