Author Topic: HOW-TO: Add WiFi to your arduino projects with ESP8266  (Read 13833 times)

0 Members and 1 Guest are viewing this topic.

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
HOW-TO: Add WiFi to your arduino projects with ESP8266
« 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!
« Last Edit: August 09, 2015, 06:55:38 PM by Dave »

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #1 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
« Last Edit: August 09, 2015, 03:22:14 PM by Dave »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #2 on: August 05, 2015, 12:49:04 PM »
 ::bow  Great work Dave!
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #3 on: August 05, 2015, 12:55:02 PM »
I'm looking forward to seeing "Option 2" !
« Last Edit: August 05, 2015, 10:54:42 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #4 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?

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #5 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?
« Last Edit: August 05, 2015, 10:54:11 PM by jitterjames »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
***********  get excited and make things  **********

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #7 on: August 09, 2015, 03:25:44 PM »
Option 2 is now available!  :)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #8 on: August 09, 2015, 05:11:31 PM »
Awesome.  Looks pretty straightforward.

Thanks Dave!  :hugs

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #9 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?
« Last Edit: August 09, 2015, 05:41:54 PM by jitterjames »

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFI to your arduino projects with ESP8266
« Reply #10 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)!

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #11 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
***********  get excited and make things  **********

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #12 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
« Last Edit: December 29, 2015, 10:05:12 AM by mexicanto »

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #13 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.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #14 on: December 29, 2015, 04:53:25 PM »
***********  get excited and make things  **********

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #15 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
« Last Edit: December 30, 2015, 01:24:52 AM by mexicanto »

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #16 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


Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #17 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>
***********  get excited and make things  **********

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #18 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

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #19 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&&" ...
***********  get excited and make things  **********

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #20 on: January 14, 2016, 05:36:49 AM »
Thanks again Kalle,

I will try that tomorrow and share my results

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #21 on: January 14, 2016, 09:49:40 AM »
Why all the quotation marks Kalle?

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #22 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())+"&&"+...
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #23 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"
« Last Edit: January 14, 2016, 10:47:22 AM by jitterjames »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #24 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.
***********  get excited and make things  **********

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #25 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.

rajibgupta

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #26 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 ?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #27 on: April 09, 2016, 08:18:20 AM »
Can you use your router to view connected clients?

rajibgupta

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #28 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 ?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #29 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?

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #30 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 to find the IP.
« Last Edit: April 09, 2016, 09:04:22 AM by Dave »

rajibgupta

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #31 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 ?

rajibgupta

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #32 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.

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #33 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

rajibgupta

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #34 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.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #35 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
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #36 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?

rajibgupta

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #37 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.

Dave

  • $upporter
  • Sr. Member
  • *****
  • Posts: 139
  • Karma: 31
    • View Profile
Re: HOW-TO: Add WiFi to your arduino projects with ESP8266
« Reply #38 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?