SOLVED: ESP-01 driving me crazy.....

Hi,

Just signed up for this board in the hope that someone can help me out.
I have been experimenting the last three days using many sources (also this one) as a guidance to get my ESP8266-01 working nicely.

What I have:

  1. Arduino UNO
  2. ESP-01 (firmware 1.5.4)
  3. DHT22 temp/humidity sensor.

What I’m trying to achieve:
Periodically capture the data coming from my sensor, and send it via Wifi to my MQTT server. I’m using this URL :
Temperature upload over MQTT using Arduino UNO, ESP8266 and DHT22 sensor | ThingsBoard Community Edition to get it working.

What goes wrong:
I honestly do not know…
Whenever I load the BareMinimum sketch, and I use the AT commands on 115200 baud, I can connect with my Wifi router without any problems. Even when the external power is not connected to the Arduino !

For this piece of code I use AT+CIOBAUD=9600 to force the ESP-01 to talk on 9600 baud.
The relevant code in the project is :

 Serial.begin(9600);
  dht.begin();
  InitWiFi();

in setup(), and:

 soft.begin(9600);
WiFi.init(&soft);
Serial.println(WIFI_AP);
status = WiFi.begin(WIFI_AP, WIFI_PASSWORD);

Of course, WIFI_AP and WIFI_PASSWORD are defined elsewhere in the code…

The header files used are:

#include "DHT.h"
#include <WiFiEspClient.h>
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>
#include <PubSubClient.h>
#include "SoftwareSerial.h"

Whatever I try, no connection is ever made to my AP:

[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
WiFi shield not present

Can someone please explain why manually issuing AT commands works, but using WiFi libraries in a sketch does not ?
Would be most grateful…

Thanks
Hans

There's probably something wrong with your connection, or your baud rate, or both. (CIOBAUD is not permanent, IIRC, and you have to swap RX and TX.)

But most of all: AT commands are garbage. Throw out the UNO, connect the DHT22 to the ESP, and program it directly.

A Beginner's Guide to the ESP8266

Pieter

Thanks Pieter,

Ok, I'll try the RX/TX swap...
And for the UNO..I need the UNO because it has to control relays that water my plants in my greenhouse, based on the temparature and humidity readings...

Hang on...
I swapped RX and TX and now I see the sketch trying to connect to my AP. Wifi init was sucessful !
Now hoping it can connect....

Thanks again,
Hans

noiasca:
Agree. don't mess around with AT-commands. If you need more GPIO's use something like the more userfriendly Wemos or NodeMCU.

+1
Even if you really have to use an Arduino, use it as a slave. The ESP8266 is a much, much more powerful microcontroller than the Arduino UNO.

Also, you aren't running SoftwareSerial on pins 0 and 1, are you?

No I'm not using softwareserial on 0,1...
And I am connected. The sensor is happilt sending data over Wifi to MQTT.....Great success !

Just starting out with this IoT stuff, and it's fun.
When it works.
Any hints on where to find documentation on how to use the uno as a slave to the esp ?

Didn't know that was possible, but for now I don't see how I can achieve my plant watering system without the help of an arduino to control my relais....

Using the ESP8266-01 as a WiFi module attached to an Uno should be straightforward. You may not have all the capabilities that you get by directly programming the ESP8266, but you should not need them for simply sending temperature data.

On the other hand, learning to program the ESP8266 directly will broaden your skill set.

…R

phloks:
Just starting out with this IoT stuff, and it’s fun.
When it works.
Any hints on where to find documentation on how to use the uno as a slave to the esp ?

Didn’t know that was possible, but for now I don’t see how I can achieve my plant watering system without the help of an arduino to control my relais…

Have a look at the link I posted, it explains everything you need to know to program the ESP like an Arduino. Then it’s just a matter of getting it to communicate with the Arduino: this can be simply done over serial, for example. Take a look at Robin2’s Serial Input Basics.
You can then just send something like “<R1|1>” to turn on relay 1, for example. All the UNO has to do, is read the commands from the ESP, and turn on/off the appropriate pins.

But you could probably do it without the UNO: an ESP-01 has 4 IO pins (you can use TX and RX as well).
If you do need more pins (up to 11), you can get a Wemos D1 mini or similar for around $3. It’s an ESP8266 that breaks out all available pins.
It’s dirt cheap, and much easier than having to communicate between two microcontrollers.

Thank you guys for all the support and hints.
You certainly have broadend my horizon and made me aware of other possibilities I didn’t know were possible.
On the other hand I don’t like you because now I will have to spend even more time away from the wife…

Just kidding…

Thanks again, and I’ll mark this one as solved.