ESP8266-01 with Arduino Uno, problem with WIFI connection

Hello Community,

I am using a ESP8266-01 connected to an arduino uno as it can be seen here: esp01-connections hosted at ImgBB — ImgBB

I uploaded a blank sketch to the arduino and I am able to run all this AT commands and even connect succesfully to wi-fi as I can see in the Arduino IDE's serial monitor: ATOK-------------------------------------------------Returns MACAT+CIP - Pastebin.com

After that I moved the pins 2 and 3 to 7 and 6 and I used an online graphical site for coding where I can download the generated files: www.arduinoblocks.com

The problem is when the arduino tries to connect to wifi this happens (as I can see this in the IDE's serial monitor):

⸮[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Initilization successful - 2.0.0
Attempting to connect to WPA SSID: Atomos
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Failed connecting to Atomos
Attempting to connect to WPA SSID: Atomos
[WiFiEsp] Connected to Atomos
Attempting to connect to WPA SSID: Atomos
[WiFiEsp] Connected to Atomos

and it keeps going like that... Maybe I can add some lines to the code so I can have more feedback to see exactly what is the problem? I suppose it can be that the module does not get an IP but how I can be sure?

Here is the .ino file: /* ArduinoBlocks.com *//* Project: wifi */#include <SoftwareSerial.h># - Pastebin.com

I also have this other 26 files that come with it (the numbers before the file names are the sizes in kb): m@m:~/Desktop/arduinoblocks553928$ ls -stotal 192 4 ABlocksIOTArduinoDefines - Pastebin.com

I uploaded them here as a single .zip file: 40.6 KB file on MEGA

But if you prefer I can put them in pastebin or provide them in some other way. I did not put them here as it will be too long.

Many thanks

Marcelo

You can post that here.
Personally i don't support the use of AT-commands initiated from a sketch a different machine (like a Mega)
It is to cumbersome and inefficient compared to programming the ESP directly.

OK Deva_Rishi, I am posting the .ino file here as you suggested:

/* ArduinoBlocks.com */
/* Project: wifi */
 
#include <SoftwareSerial.h>
 
#include "ABlocksIOTMQTTESP8266.h"
 
double ordenes;
 
String s_ordenes;
 
const char mqtt_broker[]="io.adafruit.com";
const int mqtt_port=1883;
const char mqtt_user[]="lw3eov";
const char mqtt_pass[]="whatever";
const char mqtt_clientid[]="lw3eov";
const char mqtt_wifi_ssid[]="Atomos";
const char mqtt_wifi_pass[]="whatever";
//ABlocksIOT: esp8266
SoftwareSerial mqtt_esp8266_serial(7,6);
ESP8266 mqtt_esp8266_wifi(&mqtt_esp8266_serial);
char mqtt_payload[64];
unsigned long task_time_ms=0;
 
double mqtt_payload2double(unsigned char *_payload, int _length){
	int i;
	for (i = 0; i<_length && i<64; i++){
		mqtt_payload[i] = _payload[i];
	}
	mqtt_payload[i] = 0;
	return atof(mqtt_payload);
}
 
String mqtt_payload2string(unsigned char *_payload, int _length){
	int i;
	for (i = 0; i<_length && i<64; i++){
		mqtt_payload[i] = _payload[i];
	}
	mqtt_payload[i] = 0;
	return String(mqtt_payload);
}
void mqtt_callback(char* _topic, unsigned char* _payload, unsigned int _payloadlength){
	double v=mqtt_payload2double(_payload,_payloadlength);
	String vt=mqtt_payload2string(_payload,_payloadlength);
	if(String(_topic)==String("lw3eov/f/Encenderluz"))s_ordenes=vt;
	if(String(_topic)==String("lw3eov/f/Apagarluz"))s_ordenes=vt;
}
 
void mqtt_subscribe(){
	ABlocksIOT.Subscribe(String("lw3eov/f/Encenderluz"));
	ABlocksIOT.Subscribe(String("lw3eov/f/Apagarluz"));
}
 
void setup()
{
  	mqtt_esp8266_serial.begin(9600);
	ABlocksIOT.begin(mqtt_broker,mqtt_port, mqtt_user,mqtt_pass, mqtt_clientid, mqtt_esp8266_wifi, mqtt_wifi_ssid, mqtt_wifi_pass, mqtt_callback, mqtt_subscribe);
pinMode(8, OUTPUT);
pinMode(A0, INPUT);
}
 
 
void loop()
{
	mqtt_esp8266_serial.listen(); ABlocksIOT.loop();
    if ((ordenes == 1)) {
      digitalWrite(8, HIGH);
 
    }
    if ((ordenes == 0)) {
      digitalWrite(8, LOW);
 
    }
    if((millis()-task_time_ms)>=5000){
    	task_time_ms=millis();
      mqtt_esp8266_serial.listen(); ABlocksIOT.Publish(String("lw3eov/f/NivelLuz"), String(analogRead(A0)));
    }
 
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.