AHS01: The Software
Once you’ve successfully built the kit, it’s now time to give it some brains by uploading the source code.
While it may be temping to edit the source code, please leave it unchanged until we can verify that it’s working. Once we’ve verified that it’s working, you can then change the source and repeat these steps if you wish.
Contents
Getting Started
Things we need to do
- Setup the Arduino IDE and Wemos development libraries
- Install Library dependancies in the Arduino IDE
- Upload the code to our project
Back to Contents
Setup the Arduino IDE
We wont go into detail here about how to accomplish this, simply because there is already a great article on how to do it (this is the one I originally followed!). Thanks Instructables!!!
http://www.instructables.com/id/Programming-the-WeMos-Using-Arduino-SoftwareIDE/
Once you’ve got that setup, come back here and continue reading!
Back to Contents
Install library dependancies
In the Arduino IDE, select Sketch->Include Library->Manage Libraries
The library management window should pop up, allowing you to search for libraries.
Search for and install the following
- SimpleDHT2
- WifiManager (by tzapu)
- PubSubClient (by Nick O’Leary)
Back to Contents
Upload the code
First, you’ll need to download the code here, from it’s home on github (https://github.com/alienrobotarmy/kits/blob/master/AHS01/AHS01.ino)
Next, open it up n the Arduino IDE
- Select Tools->Board->Wemos D1 R2 & Mini
- Select Port->Port of the Wemos (This depends on your OS)
- Click the Upload Icon
Once the code is uploaded to the board you should be able to open up the Serial Monitor in the Arduino IDE and see the output from the Wemos.
Back to Contents
Connect to your wireless network
By default the device will now listen in Access Point point mode and wait for you to configure it.
Find the access point by browsing the available wireless access points in your area. The access point will most likely start with ESP(number)
Once connected, a configuration page should pop up.
Click “Configure WiFi”
- Select your Home Access point.
- Enter the passphrase for your network
- Enter the MQTT hostname or IP address on your network (or leave blank)
- Enter the MQTT Pot (or leave blank)
** Leaving the MQTT setting blank will make the AHS01 operate in HTTP only mode.
Back to Contents
Access the device
Once the device is connected to your WiFi network it will start publishing to your MQTT server (If you didn’t specify one, or don’t have one you can still access it via HTTP), and be available for queries via HTTP.
HTTP URI’s include:
- /lumens
- Shows the amount of light currently read by the sensor (Integer)
- /motion
- Show the current state of the PIR motion sensor (ON / OFF)
- /blink
- Blinks the LED for 30 seconds (This can help in identifying if you have multiple sensors)
- /reboot
- Reboot the unit
- /reset
- Erase all saved settings and reboot.
Back to Contents