VoxCommando

Arduino & Other Home-made Gadgets (that work with VC!) => Arduino support => Topic started by: Dave on August 05, 2015, 12:22:38 PM

Title: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Dave on August 05, 2015, 12:22:38 PM
Option 1: Using the ESP8266 as transparent seraial bridge

What you need:
- Arduino
- ESP8266 module (e.g. ESP-01)
- FTDI with 3.3V
- computer/notebook with WiFi


That’s it!
The ESP should now connect to your network. You can find its IP e.g. with AutoScan-Network.

Connect your ESP to your Arduino (RX <-> TX, TX <->RX)
CAUTION: The ESP module works with 3.3V while most Arduinos work on 5V! Since the ESP module draws a lot of current, you will probably not be able to power it by your arduino. (The RX/TX pins seem to be 5V tolerant and I connect them directly to my (5V) arduino, try at own risk.)

You can now send messages to the serial port of your arduino with the VC action TCP.Single.WriteLn! You need to add the IP of your ESP and use port 23. Make sure to append \x0A to every message!

Have fun!
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: Dave on August 05, 2015, 12:23:03 PM
Option 2: ESP as stand alone chip. Programming the ESP with Arduino IDE

What you need:
- ESP8266 module (e.g. ESP-12)
- FTDI with 3.3 V


Note 1: Some libraries might not work!
Note 2: Pin numbers match GPIO numbers!

You can find a simple sketch with an web server to toggle an LED here:
http://www.esp8266.com/viewtopic.php?f=29&t=3787 (http://www.esp8266.com/viewtopic.php?f=29&t=3787)
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: Kalle on August 05, 2015, 12:49:04 PM
 ::bow  Great work Dave!
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: jitterjames on August 05, 2015, 12:55:02 PM
I'm looking forward to seeing "Option 2" !
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: jitterjames on August 05, 2015, 12:58:43 PM
You can now send messages to the serial port of your arduino with the VC action TCP.Single.WriteLn! You need to add the IP of your ESP and use port 23. Make sure to append \x0A to every message!

What about receiving messages back from the Arduino?  We previously used an event generated by the serial port.  Will we now get a TCP event?  In order to do this, we would need to use TCP.Client instead of TCP.Single?
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: Dave on August 05, 2015, 01:06:20 PM
What about receiving messages back from the Arduino? 

I did not try this. I will report back as soon as possible. Or maybe Kalle could try it, since I'm not at home the next few day?
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: Kalle on August 05, 2015, 01:30:38 PM
Here is also some text to the picture: https://importhack.wordpress.com/2014/11/22/how-to-use-ep8266-esp-01-as-a-sensor-web-client/
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: Dave on August 09, 2015, 03:25:44 PM
Option 2 is now available!  :)
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: jitterjames on August 09, 2015, 05:11:31 PM
Awesome.  Looks pretty straightforward.

Thanks Dave!  :hugs
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: jitterjames on August 09, 2015, 05:37:31 PM
So for option2, we don't need to flash the firmware first?  Does that mean then that we do not connect GPIO0 to ground?

Or are we effectively flashing the unit every time we program it from the Arduino IDE?
Title: Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
Post by: Dave on August 09, 2015, 06:54:45 PM
We are flashing the firmware every time we upload a new sketch, so you have to connect GPIO0 to GND first (before powering the module)!
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on August 28, 2015, 04:12:33 AM
Now it looks like the MySensors stuff is ported to the ESP8266  :yay

http://forum.mysensors.org/topic/1870/esp8266-wifi-gateway-port-for-mysensors/1
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: mexicanto on December 29, 2015, 09:59:23 AM
Hello Dave,

By any chance, do you have an example/code that you can share ?

I refer to the option 1, esp8266 + arduino (the mini pro 3.3v)

I am trying to turn on/off a led, reading an analog value and trigger an event with a push button

Any help will be greatly appreciated
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Dave on December 29, 2015, 04:41:31 PM
Hi mexicanto,
sorry, I don't have any example code. What you want to do should be possible in theory, but I never tried sending messages from arduino to VC using the serial bridge method. I don't use this method anymore at all. As long as you only need one analog input I would recommend using method 2 e.g. with a nodemcu board.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on December 29, 2015, 04:53:25 PM
@mexicanto


you can take a look in this forum: http://www.esp8266.com/viewforum.php?f=27&sid=b51604943ad23bb6b1dc399a4fc9c354
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: mexicanto on December 30, 2015, 12:34:26 AM
Thank you Dave and Kalle,

I need both, sending and receiving from/to VC-Arduino
because i need all the 3 pins (at least) (1 analog +  1 button + led)
this post is my project

http://voxcommando.com/forum/index.php?topic=1679.msg21000#msg21000

Kalle, I was reading that forum, but thank you for your support, is greatly appreciate
I'm going to experiment with the module and arduino, and I will post my results

thanks again, and happy new year
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: mexicanto on January 14, 2016, 04:00:51 AM
Hi Everybody,

I am working witha esp8266-01
i am able to turn on and off a led if i open a web browser and type:

http://192.168.1.2/gpio/1         

http://192.168.1.2/gpio/0

on and off, respectively
and the web page respond:

GPIO is now high

GPIO is now low

respectively too

I have tried this in the LCB

TCP.Single.WrileLn             /gpio/1\x0a                 192.168.1.2          80

with no success, any help will be greatly apreciate

thanks

Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on January 14, 2016, 04:11:58 AM
You must use the scrape action in the LCB.


Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.9-->
<command id="386" name="ESP8266" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.1.2/gpio/1</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>the LED is now ON</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>set pin to high</phrase>
</command>
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: mexicanto on January 14, 2016, 05:17:53 AM
It works perfect !!!

Thank you very much Kalle !!!

Also, any suggestion to do the opposite ?? push a button on the esp8266
and generate an event on VC ?

I know i have to program the ESP8266 as a server, not a client

thanks again
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on January 14, 2016, 05:32:41 AM
If you are able to program the udp function on the ESP, you can send a message which starts with  -  "VC.TriggerEvent&&""event name&&""payload1&&""payload2&&" ...
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: mexicanto on January 14, 2016, 05:36:49 AM
Thanks again Kalle,

I will try that tomorrow and share my results
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: jitterjames on January 14, 2016, 09:49:40 AM
Why all the quotation marks Kalle?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on January 14, 2016, 09:59:43 AM
Haha sorry - this is how it looks in the arduino code:


String udpMsg = "VC.TriggerEvent&&""RF read&&"+String(mySwitch.getReceivedValue())+"&&"+...
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: jitterjames on January 14, 2016, 10:45:13 AM
Still looks wrong to me.  Is there something wrong with your browser?

Shouldn't it be more like this?
Code: [Select]
String udpMsg = "VC.TriggerEvent&&EventName&&"+String(mySwitch.getReceivedValue())+"&&Payload2Here"
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on January 14, 2016, 11:33:01 AM
No, with my browser is everything ok. I copied the code from our blaster sketch and it works fine.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Dave on January 14, 2016, 12:47:43 PM
Kalle, James is right. The two quotation marks between "...&&" and "RF read&&" are not needed and don't make sense.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: rajibgupta on April 09, 2016, 08:00:40 AM
Hello,

I flashed this firmware and everything is working perfectly. But after I enter the wifi ssid and password,it gets connected but how do I find the IP address ? Does it have an AT command to get the IP address info ?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: jitterjames on April 09, 2016, 08:18:20 AM
Can you use your router to view connected clients?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: rajibgupta on April 09, 2016, 08:50:58 AM
Yes,I can do that but that is not a convenient way to do that because there are thousands of types of routers and each having different settings .

By the way, can this firmware support uploading program to arduino over the air ?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: jitterjames on April 09, 2016, 09:00:09 AM
That’s it!
The ESP should now connect to your network. You can find its IP e.g. with AutoScan-Network.

Presumably you only have one router...

Anyway did you try AutoScan-Network as suggested in the instructions?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Dave on April 09, 2016, 09:01:53 AM
Are you using the ESP as bridge for an arduino or are you using it as a stand alone chip? For the second option it is possible to integrate OTA updates.

I'm using the ESP mostly with a static IP, but if not you can use e.g Network Scanner:
http://www.heise.de/download/network-scanner-ee167ca09e83ae01b01f10e9710d23a3-1460199860-2613270.html (http://www.heise.de/download/network-scanner-ee167ca09e83ae01b01f10e9710d23a3-1460199860-2613270.html) to find the IP.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: rajibgupta on April 09, 2016, 09:09:54 AM
I have 3 different routers in my office and another router at home. so I was trying to find another way.

I did not exactly get that part. Where do I do the autoscan thing ?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: rajibgupta on April 09, 2016, 09:14:02 AM
Dave, I am using it as ESP-bridge connection. Giving it a static IP would be a good idea but how do I give it a static IP ? I will try the autoscanner thing.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Dave on April 09, 2016, 10:10:10 AM
Sorry, I'm only using the ESP as stand alone chip. I don't think there is an easy way to use static IP with the serial bridge. For more information you should have a look at the Github page: https://github.com/beckdac/ESP8266-transparent-bridge
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: rajibgupta on October 07, 2016, 03:55:57 AM
Hey guys,

Could anyone tell me how to know the connection status ? Are there any AT commands for that ?
I am using the option 1.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Kalle on October 07, 2016, 05:15:51 AM
Maybe this posting can help you, but only if your ESP use a static IP

http://voxcommando.com/forum/index.php?topic=1301.msg11234#msg11234 (http://voxcommando.com/forum/index.php?topic=1301.msg11234#msg11234)
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: jitterjames on October 07, 2016, 09:01:00 AM
Hey guys,

Could anyone tell me how to know the connection status ? Are there any AT commands for that ?
I am using the option 1.

Do you want to know the status from VoxCommando's point of view or from within your Arduino code?
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: rajibgupta on October 08, 2016, 03:10:47 AM
What is voxcommando's point of view ?

I am using the option 1, so just burning the transparent bridge firmware. Not using any arduino code.
Title: Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
Post by: Dave on October 08, 2016, 06:52:16 AM
+++AT STA  should print the SSID (and password) of the router the ESP is connected to. Is that what you are looking for?