This code serves as my starting point for any ESP8266 projects (either on Wemos, Sonoff, MagicLight, etc). In itself, this code doesn't do much, after flashing the ESP8266 will become a wifi hotspot and allow for configuration, however most of the magic happens in code you need to write on top of this.
This was written in Arduino 1.6.5 with the ESP8266 libraries installed.
- OTA Firmware Updates
- TZapu's WifiManager
- PubSub Client
If you've never worked with the Wemos before and are using OSX/Windows, then you'll need to download the CH340 USB->Serial driver for your OS. Google to find the appropriate driver. Most other cheap ESP8266 boards are using this chip as well, so this will probably be required if you're using the NodeMCU or other board.
Out of the box, Arduino is missing a compiler for the ESP8266, as well as some libraries which we will use later.
-
In Arduino, under Edit -> Preferences add the following URL to the "Additional Boards Manager URLs" field: http://arduino.esp8266.com/stable/package_esp8266com_index.json
-
Under Tools → Board → Boards Manager search for ESP8266 and click Install
-
In the Library Manager (Sketch → Include Library → Library Manager), search for and install the latest of:
- PubSubClient
- ArduinoJSON
- (Probably useful: Infrared remote libraries)
-
Download Ken Taylor's WifiManager from https://github.com/kentaylor/WiFiManager and extract it to the Arduino Libraries folder
With the above libraries and configuration, you should be able to upload + run this code on the ESP8266; You will need to adjust the setup()
and loop()
functions to actually do what you want to accomplish. Check out some of my branches which I use for various lights or sensornodes for inspiration.