mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-11 02:12:53 +00:00
working on posts
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
<div class="blog-post">
|
||||
|
||||
<h2 id="title" class="blog-post-title">ESP8266 - Cheap Wifi Microcontroller</h2>
|
||||
|
||||
<p id="date" class="blog-post-meta">August 13, 2015 by Mitchell</p>
|
||||
|
||||
<p id="intro">I've recently started playing around with microcontrollers, or more specifically arduinos. I have always had some projects in mind that require the use of some sort of microcontroller, most of which requred a wifi connection. There are a few wifi options availabe for the arduino, some of which can be very expensive. I eventually stumbled upon the ESP8266, which I have finally figured out... mostly.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Why the ESP8266?</h3>
|
||||
|
||||
<p>It is extremely cheap! They can be found for roughly $3 apiece whereas the wifi arduino shield is around $70! I figured I would take my chances with the cheaper option and I ordered <a href="http://www.banggood.com/ESP8266-Remote-Serial-Port-WIFI-Transceiver-Wireless-Module-p-947259.html">three of these</a>. After frying two of these in process of trying to figure the darn things out, I ordered a <a href="http://www.banggood.com/ESP8266-ESP-07-Remote-Serial-Port-WIFI-Transceiver-Wireless-Module-p-968190.html">5 pack of the ESP-07 version.</a> Banggood also sent me 7 of them which was a bonus.
|
||||
|
||||
<h3>Why the ESP-07 version?</h3>
|
||||
|
||||
<p>The ESP8266 can be programmed as a stand alone device with the <a href="https://github.com/esp8266/Arduino">Arduino IDE!</a> That's right, you don't even need an arduino! Also, most of the arduino libraries work with it! I went this direction after exeriencing many frustrations using the ESP8266 in conjunction with an arduino. The ESP-07 version has more GPIO pins and is about the same price, whereas the ESP-01 only has two GPIO pins, one of which much be grounded to program the device.
|
||||
</p>
|
||||
|
||||
<h3>First experiences with the ESP8266</h3>
|
||||
<p>After playing around with this microcontroller for some time now, I have concluded that it can be finicky at times. Documentation for the device can also be difficult to find, especially if you run into problems. I am going to discuss what I went through to finally get the device fully working, along with the frustrations that I experienced.
|
||||
</p>
|
||||
|
||||
<p>When you first get the device, make sure to have solid connections to each one of the pins. You will need an FTDI programmer to connect to USB. <a href="http://www.banggood.com/FT232RL-FTDI-USB-To-TTL-Serial-Converter-Adapter-Module-For-Arduino-p-917226.html">This is the one that I have and it works fine.</a> Just make sure you have one that is 3.3v capable or it will not work! The ESP8266 can draw over 200 mA at times and the FTDI programmer simply does not provide enough power. <a href="http://www.banggood.com/3Pcs-MB102-Breadboard-Module-Adapter-Shield-3_3V5V-For-Arduino-Board-p-957095.html">This is the power supply I used.</a>
|
||||
</p>
|
||||
|
||||
<h3>Wiring</h3>
|
||||
<p>Wiring is pretty much the same across different versions of the ESP8266. Connect VCC and CH_PD to power at all times. Gnd to gnd and on the ESP-07 GPIO15 must also go to gnd. When you program the device, you must have GPIO0 to ground for programming mode. You must also connect RX on the ESP8266 to TX on the FTDI programmer and vice versa. Make sure to connect all of the power and ground wires to the power supply and NOT the FTDI programmer. The only two wires you should have connected to the FTDI programmer are RX and TX.
|
||||
</p>
|
||||
|
||||
<h3>Testing the ESP8266</h3>
|
||||
<p>To test out the device, plug it into your computer and use a serial monitor. You can use the arduino serial monitor, or you can also use putty. Make sure to select the correct COM port and the right baud rate. Baud rates can vary. I have had some that are 9600 and others have been 115200. Just change the baud rate until you see text that you can actually read. Once connected, you can change the baud rate of the ESP8266.
|
||||
</p>
|
||||
<p>There is a set of AT commands to communicate with the ESP8266. The documentation of these commands is descent although some commands were a bit hard to find. <a href="https://nurdspace.nl/ESP8266">Here is a list of most of the commands.</a> A few important commands that are often missed are to change the baud rate and update the firmware on the device. You can update the firmware by using AT+CIUPDATE. You can also change the baud rate by using AT+CIOBAUD=9600, or whatever baud rate you desire.
|
||||
</p>
|
||||
|
||||
<p>These commands can be used to test the ESP8266, but they are also the same commands if you wanted to use it with an arduino. Simply wire it up to serial on an arduino and print out the commands. I played around with this for a bit, but not long enough to get it fully working. This is how I was originally going to use the device, but I found it to be much easier programming the ESP8266 directly as a standalone device.
|
||||
</p>
|
||||
|
||||
<h3>Programming ESP8266 with Arduino IDE</h3>
|
||||
<p>A major advantage of programming the ESP8266 is that it is more powerful, yet much smaller in size. It uses a 32 bit processor and also has 1mb of ram (on the newer versions). <a href="https://github.com/esp8266/Arduino">Link to Github ESP8266 Arduino IDE.</a> You can install this in your Arduino IDE by File > preferences and adding <code>http://arduino.esp8266.com/package_esp8266com_index.json</code> to Additional Boards Manager URLs. Now you can go to Sketch > Libraries > Manage Libraries and add the ESP8266 library.
|
||||
</p>
|
||||
|
||||
<p>Select an example sketch (WIFIScan) and make sure your ESP8266 is plugged in with GPIO0 to ground! It must be to ground to enter programming mode! Select Generic ESP8266 Module for the board and the right port. It shouldn't matter which programmer is selected. Compile and upload your sketch and it is as simple as that!
|
||||
</p>
|
||||
|
||||
<h3>Complications</h3>
|
||||
<p>I just want to reiterate some of my complications that I ran into throughout this process. The biggest thing to keep in mind it to check your connections! The first time I soldered all of the connections I couldn't figure out why it wasn't working. I checked each connection with a meter only to find out one of them was bad. Another thing is to make sure you use an external power supply! Connect all power and ground connections to these! Also connect the ground of your FTDI programmer to the ground of your power supply. Make sure the voltage of your power supply and FTDI programmer are 3.3v! Remember to connect GPIO0 to ground ONLY when uploading to the ESP8266.
|
||||
</p>
|
||||
<h3>Sources</h3>
|
||||
|
||||
<a href="https://www.sparkfun.com/products/13678">https://www.sparkfun.com/products/13678</a>
|
||||
<br>
|
||||
<a href="http://www.esp8266.com/">http://www.esp8266.com/</a>
|
||||
<br>
|
||||
<a href="https://github.com/esp8266/Arduino">https://github.com/esp8266/Arduino</a>
|
||||
<br>
|
||||
<a href="http://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf">http://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf</a>
|
||||
<br>
|
||||
<a href="https://nurdspace.nl/ESP8266">https://nurdspace.nl/ESP8266</a>
|
||||
<br>
|
||||
<a href="http://www.electrodragon.com/w/ESP8266">http://www.electrodragon.com/w/ESP8266</a>
|
||||
</div>
|
||||
@@ -1,91 +0,0 @@
|
||||
<div class="blog-post">
|
||||
<h2 id="title" class="blog-post-title">Wifi Controlled LED Lights</h2>
|
||||
|
||||
<p id="date" class="blog-post-meta">October 28, 2015 by Mitchell</p>
|
||||
|
||||
<p id="intro">LED lights can be used for many different things. I have used LED lights in the past in my computer and even on my desk. They have always been wired to a physical switch. I now have LED lights that I can turn on and off and even change color from a simple web page that I can access with my phone.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>For this project I used the ESP8266 microcontroller to connect to my wireless network, run a web server, and control an RGB LED strip based on inputs from a web form. I followed <a href="https://learn.adafruit.com/rgb-led-strips">this guide</a>, but incorporated Wifi to control the LEDs.
|
||||
</p>
|
||||
|
||||
<p>Required Components
|
||||
</p>
|
||||
|
||||
<p>ESP8266 <br>
|
||||
12v Powersupply 1.2 Amps per meter (Keep in mind the ESP8266 can draw 200-400ma) <br>
|
||||
Wiring <br>
|
||||
<a href="http://www.banggood.com/10-Pcs-TIP120-NPN-TO-220-Darlington-Transistors-p-932779.html">TIP120 Transistors</a> <br>
|
||||
12v to 3.3 volt converter
|
||||
|
||||
</p>
|
||||
|
||||
<br>
|
||||
|
||||
<p>Code can be found <a href="https://github.com/mgerb/wifi_leds/blob/master/wifi_RGB_strip.ino">here</a>.</p>
|
||||
|
||||
<div>
|
||||
<script src="https://gist.github.com/mgerb/7858a3d20041dd94c841.js"></script>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<h3>Code</h3>
|
||||
<p>Depending on which version of ESP8266 you have, this might not work. You need at least 3 GPIO pins. I used version ESP-07, which has plenty of usable GPIO pins. The code is fairly simple. Basic functionality includes connecting to my Wifi network and starting up a web server. I was able to log into my router after the ESP connected to assign it a static IP. This way I could always access the web server with the same IP address.
|
||||
</p>
|
||||
|
||||
<p>The main program loop listens for an http request on the web server. If the cycle parameter is set to true, the color cycle function will continue to run until the server gets another HTTP request. The color cycle function happens to be a problem because it does not run asynchronously. This means that the whole color cycle must complete before it can respond to another HTTP request. This can cause delays when accessing the web page. Because this is a small personal project I didn't look into fixing this issue.
|
||||
</p>
|
||||
|
||||
<p>All data from the web page is passed to the server through get parameters. The program parses through these parameters and checks to see if any of the colors are out of range. If they are out of range it either sets them to a max value of 250 or a min value of 0 (off). The changeColor method is called with paramters from the web form.
|
||||
</p>
|
||||
|
||||
<h3>Changing Colors</h3>
|
||||
|
||||
<p>The changeColor function takes in 6 parameters; one for current color and one for each color passed from the web form. This function needs the current color because it implements the changing of colors gradually. Again, it is all synchronous so during the changing of colors the web server will not be able to respond to requests.
|
||||
</p>
|
||||
|
||||
<h3>Cycling Colors</h3>
|
||||
<p>The color cycle function is a bit more confusing than the changeColor function. This function cycles through each color once. The delay can be adjusted to how fast you would like the cycle to last. This function will continuously get called as long as the cycle boolean is true. After each cycle the server will still check for an http request. Like I mentioned above this function is synchronous so it must complete a full cycle before any other code is executed.
|
||||
</p>
|
||||
|
||||
<p>This function is only chaning 2 RGB values at any one time. It contains two loops, one of which is nested. The first loop selects two pins to be cycled at one time: rgbColor[decColor] and rgbColor[incColor]. For example, it will first select Red and Green, then Green and Blue, and finally Blue and Red. During each selection, a nested loop is run, which cycles the color values of selected color pins. Red starts at 250 where Green starts at 0. The nested loop cycles Red to 0 while cycling Green to 250, exits the nested loop, and then proceeds to cycle Green and Blue, and finally Blue and Red.
|
||||
</p>
|
||||
|
||||
<h3>Wiring</h3>
|
||||
|
||||
<p>The wiring for this project is fairly straight forward. The image below is from Adafruit's website and it illustrates the wiring for an Arduino. The ESP8266 wiring is fairly similar, but because it runs on 3.3 volts, I have used two regulators to convert 12 volts. I used a 5v and 3.3v regulator because the 3.3v regulator could not take 12v as an input. You could also just get a 12v to 3.3v converter but I used what I had on hand.
|
||||
<br>
|
||||
<br>
|
||||
12v PSU > 5v > 3.3v > ESP8266
|
||||
<br>
|
||||
<br>
|
||||
The power on the LED strip is wired straight to the positive connections on the 12v power supply.
|
||||
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<img class="img-responsive" src="https://learn.adafruit.com/system/assets/assets/000/002/692/medium800/led_strips_ledstripfet.gif?1396785823" alt="image">
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<p>The image below is how I have my ESP8266 wired under my desk to control my led lights. As you can see the power comes in from the top right and the output for each RGB pin is on the left where the black is the 12v.
|
||||
</p>
|
||||
|
||||
|
||||
<div>
|
||||
<img class="img-responsive" src="http://i.imgur.com/4p5CKOL.jpg" alt="image2">
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<p>A picture of the final setup. I have one long LED strip along the back of the desk and two smaller strips on the back of each of the monitors.
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<img class="img-responsive" src="http://i.imgur.com/aI5clZW.jpg" alt="image2">
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,50 +0,0 @@
|
||||
<div class="blog-post">
|
||||
<h2 id="title" class="blog-post-title">Temperature Sensor on the Web</h2>
|
||||
|
||||
<p id="date" class="blog-post-meta">December 18, 2015 by Mitchell</p>
|
||||
|
||||
<p id="intro">The temperature readings that are displayed on this site come from the ESP8266 with a DHT11 sensor attached to it. I am going to explain the steps in the entire process. I will split it up into two parts. In this post I will focus on programming the ESP8266 and how to send data to a web server.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p><span class="colorRed">Update:</span> I have updated some information regarding this project. Refer to these other posts.
|
||||
</p>
|
||||
|
||||
<a href="/?post=12-29-15.html">ESP8266 temperature sensor updates and difficulties</a>
|
||||
<br>
|
||||
<a href="/?post=1-1-2016.html">Temperatue Sensor - Server Side</a>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<p>For this project you will need an ESP8266 and a DHT temperature sensor. For prototyping purposes I prefer to use the <a href="http://www.banggood.com/NodeMcu-Lua-ESP-12E-WIFI-Development-Board-p-985891.html">NodeMCU module</a>. There are a variety of temperature sensors that you could use, but I prefer the DHT11 because it is easy to use and it is cheap! I ordered a 5 pack of them from <a href="http://www.banggood.com/5Pcs-KY-015-DHT11-Temperature-Humidity-Sensor-Module-For-Arduino-p-983263.html">Banggood</a>. The source code for this project can be found on <a href="https://github.com/mgerb/esp8266-HTTPTempSensor">Github</a>.
|
||||
</p>
|
||||
|
||||
<h3>How it works</h3>
|
||||
|
||||
<p>When the ESP first boots up, it reads WiFi credentials from the EEPROM and tries to connect to an access point using those credentials. If no connection is made, it starts up it's own access point and runs a web server with a captive portal. This means that when anyone connects to it, it will redirect any dns request to itself, which forces anyone to the configuration page. The user can connect to the access point and enter in the ssid, password, and preferred sensor name. This information will be saved into EEPROM and the ESP will then reboot and start sending sensor data to the server.
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<img class="img-responsive center" src="http://i.imgur.com/PhnDEyU.png" alt="image2">
|
||||
</div>
|
||||
|
||||
<h3>ESP8266 File System</h3>
|
||||
|
||||
<p>To run the web server, I used the file system library within the arduino ESP library. This is how I store the web content in flash on the chip. It allows me to modify all of the necessary web files without having to deal with sending them as strings from the arduino code.
|
||||
</p>
|
||||
<p>To use the file system, you must download the tool <a href="https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.1.3/ESP8266FS-0.1.3.zip">here</a> to upload your files to the ESP. Once downloaded, store it in a tools folder in the arduino folder (path "/Arduino/tools/ESP8266FS/tool/esp8266fs.jar"). Now when you create a new sketch go to the sketch folder and create a "data" folder. To upload data to this folder select "Tools > ESP8266 Sketch Data Upload" and the files will be uploaded to the ESP and will be ready to use within the program. More information on the ESP8266 file system can be found <a href="http://esp8266.github.io/Arduino/versions/2.0.0/doc/filesystem.html">here</a>.
|
||||
</p>
|
||||
|
||||
<h3>Sending data to the server</h3>
|
||||
|
||||
<p>There are many ways to send the data to a server, but I implemented data transfer with a simple get request. I chose this route because it is extremely simple to create a REST API in Node.js. I will cover this in a nother post. If you are unfamiliar with a get request, it is a way a web server can receive a request, and also parameters within that request. In this case, I send temperature, humidity, location, and a key as parameters in the request.
|
||||
</p>
|
||||
|
||||
<p>If this were a full production application, this would not be the ideal way to handle data transfer to a server because it is not encrypted. A better practice would be to implement this using another TCP transfer protocol. In my case, it would be better to send a POST request over SSL, but I have not looked into that for this project yet as the method I am currently using seems to work just fine.
|
||||
</p>
|
||||
|
||||
<h2>Code</h2>
|
||||
|
||||
<script src="https://gist.github.com/mgerb/fbed7864f8617ada797a.js"></script>
|
||||
</div>
|
||||
@@ -1,72 +0,0 @@
|
||||
<div class="blog-post">
|
||||
<h2 id="title" class="blog-post-title">ESP8266 temperature sensor updates and difficulties</h2>
|
||||
|
||||
<p id="date" class="blog-post-meta">December 29, 2015 by Mitchell</p>
|
||||
|
||||
<p id="intro">I'm working on setting up new sensors now that I have been developing the back end of my website to display sensor information. Throughout this process I made updates to the current code for the project. As I continue to make progress I am overcoming obstacles as they show up.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>I changed the way that the ESP8266 sends web pages to the user via HTTP requests. Previously I made use of the file system in the ESP8266, but I changed the way I did this because I noticed that it was a bit slow handling all the requests, especially because I used bootstrap to make the user interface look pretty. Although I cut down the bootstrap to only the pieces that I needed, it was still slower than I wanted.
|
||||
</p>
|
||||
|
||||
<p>I decided to not use the file system and handle the html pages within header files. I found a fairly nice way of doing this. To do this, declare a new character array, store it in flash memory with "PROGMEM", and use the raw string literal functionality of C to escape all characters in a string as show below. This is not quite as nice a dealing with an HTML file in memory, but it is easier because you do not have to upload the files to the file system every time, which takes a good amount of time.
|
||||
</p>
|
||||
<code>const char page_html[] PROGMEM = R"=====(/*insert html here*/)=====";</code>
|
||||
|
||||
<p>This newly created page can now be sent back to the user upon an HTTP request.
|
||||
</p>
|
||||
|
||||
<code>server.send(200, "text/html", page_html);</code>
|
||||
|
||||
<p>There were a few other updates that I made. I realized that if the access point the ESP was connected to goes down, it would not try to reconnect. It will now check if it is connected to the access point every time it tries to take a temperature reading and send data. If it is not connected to the access point it will reboot. Now that it reboots, if it still cannot connect to the access point it will be stuck in config mode. I fixed this by creating a timeout. If it has been sitting in config mode for 10 minutes the device will reboot.
|
||||
</p>
|
||||
|
||||
<p>These example are show below. Keep in mind that this is not the entire program, but just the new functionality that I mentioned. The source code for the project can be found <a href="https://github.com/mgerb/esp8266-HTTPTempSensor/tree/working">here</a>.
|
||||
</p>
|
||||
|
||||
<script src="https://gist.github.com/mgerb/61882e3676688bd4fb74.js"></script>
|
||||
|
||||
<h3>Problems flashing the ESP</h3>
|
||||
<p>I previously used the ESP-07, but recently got some new ESP-12e's because of the higher flash size. I thought this would be great if I was going to make use of the file system. After spending hours and hours trying to flash these chips, I came to the conclusion that I need a better serial to USB programmer. The current one that I use came from China and was very cheap.
|
||||
</p>
|
||||
|
||||
<p>With the new version of ESP Arduino software (2.0.0), you get the option of flashing with the ck mode. This requires GPI0 > DHT and RESET > RST. My FTDI programmer did not have an RTS pin, but rather a CTS. I found that I could flash one of my chips with this and the other I could not. After doing some research I found that it may be a problem with my Mac. Unfortunately my Ubuntu image that I usually dual boot with acted up and would not boot. This left me without any other operating system to try at the time.
|
||||
</p>
|
||||
|
||||
<br>
|
||||
<img class="img-responsive center" src="http://i.imgur.com/iNacOBT.jpg" alt="image">
|
||||
<br>
|
||||
|
||||
<p>Because I was experiencing problems flashing with the new ESP8266 Arduino software, I reverted to an older version (1.6.5). In this version I was able to put GPI0 > Ground and start the ESP8266 in flash mode. This is the part where I realized I have a bad FTDI programmer. When I flash the device, it will get stuck every once in awhile. I then have to unplug everything and try again. I then tried a different programmer and it was able to work every time.
|
||||
</p>
|
||||
|
||||
<p>After a good amount of frustration I was able to get my ESP8266 flashed with my new program and I got another temperature sensor set up. Here is the wiring that I used in the sensor. Keep in mind the DHT11 sensors that I used had a 10k resistor built into them.
|
||||
</p>
|
||||
|
||||
<p>GND > GND</p>
|
||||
<p>GPI15 > GND</p>
|
||||
<p>VCC > 3.3v</p>
|
||||
<p>EN (CH_PD) > 3.3v</p>
|
||||
<p>GPIO5 > Sensor Data</p>
|
||||
|
||||
<p>The sensor VCC and Ground then were hooked up accordingly. I used an 800ma 3.3v regulator to power everything and it is working fine.</p>
|
||||
<br>
|
||||
<img class="img-responsive center" src="http://i.imgur.com/WrDh8oN.jpg" alt="image">
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
12
metadata.js
12
metadata.js
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
This script runs through each markdown post and scrapes out the title and intro.
|
||||
folder/files within posts are scanned recursively
|
||||
each post is contained within category, which is supplied by the direct parent folder
|
||||
Posts are sorted by date
|
||||
Stores all metadata in ./dist/metadata.json
|
||||
Client uses metadata to display posts on preview page
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import marked from 'marked';
|
||||
import highlight from 'highlight.js';
|
||||
@@ -40,11 +49,12 @@ function parse_dir(dir, folder_name){
|
||||
}
|
||||
}
|
||||
|
||||
//recursively parse posts directory for all markdown files
|
||||
parse_dir(dir, 'posts');
|
||||
|
||||
//sort posts by date
|
||||
json.posts.sort((a, b) => {
|
||||
return new Date(b.date) - new Date(a.date);
|
||||
return new Date(b.date) - new Date(a.date);
|
||||
});
|
||||
|
||||
//output to public path
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
"build": "webpack && babel-node metadata.js",
|
||||
"c9": "webpack-dev-server --port $PORT --host $IP --hot --content-base dist --history-api-fallback",
|
||||
"dev": "webpack-dev-server --content-base dist --inline --hot --history-api-fallback",
|
||||
"prod-linux": "export NODE_ENV=production && webpack -p",
|
||||
"prod-windows": "set NODE_ENV=production & webpack -p",
|
||||
"prod-linux": "export NODE_ENV=production && webpack -p && babel-node metadata.js",
|
||||
"prod-windows": "set NODE_ENV=production & webpack -p & babel-node metadata.js",
|
||||
"deploy": "goapp deploy",
|
||||
"serve": "goapp serve"
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
## First Blog Post
|
||||
# First Blog Post
|
||||
|
||||
My first blog post introduces this website and the motives behind it. I discuss setting up a Node.js webserver for the first time and my experiences with it thus far.
|
||||
|
||||
@@ -7,6 +7,8 @@ I have had this site up for awhile now, but I've decided to turn it into a blog
|
||||
|
||||
I already had previous experience with SQL databases and other server side scripting languages such as PHP and JSP, but I heard good things about Node.js and I wanted to familiarize myself with a NoSQL database. At first, Node.js was a bit confusing to work with and figure everything out. Now that I am starting to get the hang of Node and MongoDB I am enjoying them more and more.
|
||||
|
||||
---
|
||||
|
||||
## Setting up Node.js for the first time
|
||||
|
||||
There are multiple ways to get up and running with Node. Node uses "modules" and has some that are already built in. Others need to be installed with the NPM package manager, which will become your friend. I am going focus on installing Node.js with Express, which is a web framework for Node.js.
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
<h2 id="title" class="blog-post-title">How do I use git?</h2>
|
||||
# How do I use git?
|
||||
|
||||
<p id="date" class="blog-post-meta">July 28 2015 by Mitchell</p>
|
||||
Git is a very useful file management system that you will find very handy. There are many services that host git repositories and it can also be installed on a personal server if you so choose. I'm going to explain how to set up git and discuss some useful commands and what they do.
|
||||
|
||||
<p id="intro">Git is a very useful file management system that you will find very handy. There are many services that host git repositories and it can also be installed on a personal server if you so choose. I'm going to explain how to set up git and discuss some useful commands and what they do.
|
||||
</p>
|
||||
---
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Throughout this tutorial I am going to be focusing on <a href="http://www.github.com">Github</a>, because I find it easy to use and it is what I use most of the time. Github is just one of the many web-based git repository hosting services. It also has a nice GUI interface that may be useful to beginners, but I will mainly be focusing on git via command line. I have used both in the past and although command line may seem intimidating at first, it becomes easier and more powerful over time.
|
||||
Throughout this tutorial I am going to be focusing on [Github](http://www.github.com), because I find it easy to use and it is what I use most of the time. Github is just one of the many web-based git repository hosting services. It also has a nice GUI interface that may be useful to beginners, but I will mainly be focusing on git via command line. I have used both in the past and although command line may seem intimidating at first, it becomes easier and more powerful over time.
|
||||
|
||||
What exactly does git do? Git is basically a cloud service that you can use for your coding projects. You may be wondering why use git over other cloud hosting services such as dropbox? Git is essentially the same thing, but has many built-in utilities for coding projects specifically. For example, you can see the changes between each commit (or each time you save new changes) displayed in each file. Github has a nice web interface that displays of this information. This helps with version control and it allows you to see which users have made what changes.
|
||||
|
||||
|
||||
47
posts/2015-08-13-esp8266.md
Normal file
47
posts/2015-08-13-esp8266.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# ESP8266 - Cheap Wifi Microcontroller
|
||||
|
||||
I've recently started playing around with microcontrollers, or more specifically arduinos. I have always had some projects in mind that require the use of some sort of microcontroller, most of which requred a wifi connection. There are a few wifi options availabe for the arduino, some of which can be very expensive. I eventually stumbled upon the ESP8266, which I have finally figured out... mostly.
|
||||
|
||||
## Why the ESP8266?
|
||||
|
||||
It is extremely cheap! They can be found for roughly $3 apiece whereas the wifi arduino shield is around $70! I figured I would take my chances with the cheaper option and I ordered [three of these](http://www.banggood.com/ESP8266-Remote-Serial-Port-WIFI-Transceiver-Wireless-Module-p-947259.html). After frying two of these in process of trying to figure the darn things out, I ordered a [5 pack of the ESP-07 version.](http://www.banggood.com/ESP8266-ESP-07-Remote-Serial-Port-WIFI-Transceiver-Wireless-Module-p-968190.html) Banggood also sent me 7 of them which was a bonus.
|
||||
|
||||
## Why the ESP-07 version?
|
||||
|
||||
The ESP8266 can be programmed as a stand alone device with the [Arduino IDE!](https://github.com/esp8266/Arduino) That's right, you don't even need an arduino! Also, most of the arduino libraries work with it! I went this direction after exeriencing many frustrations using the ESP8266 in conjunction with an arduino. The ESP-07 version has more GPIO pins and is about the same price, whereas the ESP-01 only has two GPIO pins, one of which much be grounded to program the device.
|
||||
|
||||
## First experiences with the ESP8266
|
||||
|
||||
After playing around with this microcontroller for some time now, I have concluded that it can be finicky at times. Documentation for the device can also be difficult to find, especially if you run into problems. I am going to discuss what I went through to finally get the device fully working, along with the frustrations that I experienced.
|
||||
|
||||
When you first get the device, make sure to have solid connections to each one of the pins. You will need an FTDI programmer to connect to USB. [This is the one that I have and it works fine.](http://www.banggood.com/FT232RL-FTDI-USB-To-TTL-Serial-Converter-Adapter-Module-For-Arduino-p-917226.html) Just make sure you have one that is 3.3v capable or it will not work! The ESP8266 can draw over 200 mA at times and the FTDI programmer simply does not provide enough power. [This is the power supply I used.](http://www.banggood.com/3Pcs-MB102-Breadboard-Module-Adapter-Shield-3_3V5V-For-Arduino-Board-p-957095.html)
|
||||
|
||||
## Wiring
|
||||
Wiring is pretty much the same across different versions of the ESP8266. Connect VCC and CH_PD to power at all times. Gnd to gnd and on the ESP-07 GPIO15 must also go to gnd. When you program the device, you must have GPIO0 to ground for programming mode. You must also connect RX on the ESP8266 to TX on the FTDI programmer and vice versa. Make sure to connect all of the power and ground wires to the power supply and NOT the FTDI programmer. The only two wires you should have connected to the FTDI programmer are RX and TX.
|
||||
|
||||
## Testing the ESP8266
|
||||
To test out the device, plug it into your computer and use a serial monitor. You can use the arduino serial monitor, or you can also use putty. Make sure to select the correct COM port and the right baud rate. Baud rates can vary. I have had some that are 9600 and others have been 115200. Just change the baud rate until you see text that you can actually read. Once connected, you can change the baud rate of the ESP8266.
|
||||
|
||||
There is a set of AT commands to communicate with the ESP8266. The documentation of these commands is descent although some commands were a bit hard to find. [Here is a list of most of the commands.](https://nurdspace.nl/ESP8266) A few important commands that are often missed are to change the baud rate and update the firmware on the device. You can update the firmware by using AT+CIUPDATE. You can also change the baud rate by using AT+CIOBAUD=9600, or whatever baud rate you desire.
|
||||
|
||||
These commands can be used to test the ESP8266, but they are also the same commands if you wanted to use it with an arduino. Simply wire it up to serial on an arduino and print out the commands. I played around with this for a bit, but not long enough to get it fully working. This is how I was originally going to use the device, but I found it to be much easier programming the ESP8266 directly as a standalone device.
|
||||
|
||||
## Programming ESP8266 with Arduino IDE
|
||||
|
||||
A major advantage of programming the ESP8266 is that it is more powerful, yet much smaller in size. It uses a 32 bit processor and also has 1mb of ram (on the newer versions). [Link to Github ESP8266 Arduino IDE.](https://github.com/esp8266/Arduino) You can install this in your Arduino IDE by File > preferences and adding `http://arduino.esp8266.com/package_esp8266com_index.json` to Additional Boards Manager URLs. Now you can go to Sketch > Libraries > Manage Libraries and add the ESP8266 library.
|
||||
|
||||
Select an example sketch (WIFIScan) and make sure your ESP8266 is plugged in with GPIO0 to ground! It must be to ground to enter programming mode! Select Generic ESP8266 Module for the board and the right port. It shouldn't matter which programmer is selected. Compile and upload your sketch and it is as simple as that!
|
||||
|
||||
|
||||
## Complications
|
||||
|
||||
I just want to reiterate some of my complications that I ran into throughout this process. The biggest thing to keep in mind it to check your connections! The first time I soldered all of the connections I couldn't figure out why it wasn't working. I checked each connection with a meter only to find out one of them was bad. Another thing is to make sure you use an external power supply! Connect all power and ground connections to these! Also connect the ground of your FTDI programmer to the ground of your power supply. Make sure the voltage of your power supply and FTDI programmer are 3.3v! Remember to connect GPIO0 to ground ONLY when uploading to the ESP8266.
|
||||
|
||||
## Sources
|
||||
|
||||
[https://www.sparkfun.com/products/13678](https://www.sparkfun.com/products/13678)
|
||||
[http://www.esp8266.com/](http://www.esp8266.com/)
|
||||
[https://github.com/esp8266/Arduino](https://github.com/esp8266/Arduino)
|
||||
[http://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf](http://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf)
|
||||
[https://nurdspace.nl/ESP8266](https://nurdspace.nl/ESP8266)
|
||||
[http://www.electrodragon.com/w/ESP8266](http://www.electrodragon.com/w/ESP8266)
|
||||
54
posts/2015-10-28-wifi-led.md
Normal file
54
posts/2015-10-28-wifi-led.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Wifi Controlled LED Lights
|
||||
|
||||
LED lights can be used for many different things. I have used LED lights in the past in my computer and even on my desk. They have always been wired to a physical switch. I now have LED lights that I can turn on and off and even change color from a simple web page that I can access with my phone.
|
||||
|
||||
* * *
|
||||
|
||||
For this project I used the ESP8266 microcontroller to connect to my wireless network, run a web server, and control an RGB LED strip based on inputs from a web form. I followed [this guide](https://learn.adafruit.com/rgb-led-strips), but incorporated Wifi to control the LEDs.
|
||||
|
||||
Required Components
|
||||
|
||||
ESP8266
|
||||
12v Powersupply 1.2 Amps per meter (Keep in mind the ESP8266 can draw 200-400ma)
|
||||
|
||||
Wiring
|
||||
[TIP120 Transistors](http://www.banggood.com/10-Pcs-TIP120-NPN-TO-220-Darlington-Transistors-p-932779.html)
|
||||
12v to 3.3 volt converter
|
||||
|
||||
Code can be found [here](https://github.com/mgerb/wifi_leds/blob/master/wifi_RGB_strip.ino).
|
||||
|
||||
## Code
|
||||
|
||||
Depending on which version of ESP8266 you have, this might not work. You need at least 3 GPIO pins. I used version ESP-07, which has plenty of usable GPIO pins. The code is fairly simple. Basic functionality includes connecting to my Wifi network and starting up a web server. I was able to log into my router after the ESP connected to assign it a static IP. This way I could always access the web server with the same IP address.
|
||||
|
||||
The main program loop listens for an http request on the web server. If the cycle parameter is set to true, the color cycle function will continue to run until the server gets another HTTP request. The color cycle function happens to be a problem because it does not run asynchronously. This means that the whole color cycle must complete before it can respond to another HTTP request. This can cause delays when accessing the web page. Because this is a small personal project I didn't look into fixing this issue.
|
||||
|
||||
All data from the web page is passed to the server through get parameters. The program parses through these parameters and checks to see if any of the colors are out of range. If they are out of range it either sets them to a max value of 250 or a min value of 0 (off). The changeColor method is called with paramters from the web form.
|
||||
|
||||
## Changing Colors
|
||||
|
||||
The changeColor function takes in 6 parameters; one for current color and one for each color passed from the web form. This function needs the current color because it implements the changing of colors gradually. Again, it is all synchronous so during the changing of colors the web server will not be able to respond to requests.
|
||||
|
||||
## Cycling Colors
|
||||
|
||||
The color cycle function is a bit more confusing than the changeColor function. This function cycles through each color once. The delay can be adjusted to how fast you would like the cycle to last. This function will continuously get called as long as the cycle boolean is true. After each cycle the server will still check for an http request. Like I mentioned above this function is synchronous so it must complete a full cycle before any other code is executed.
|
||||
|
||||
This function is only chaning 2 RGB values at any one time. It contains two loops, one of which is nested. The first loop selects two pins to be cycled at one time: rgbColor[decColor] and rgbColor[incColor]. For example, it will first select Red and Green, then Green and Blue, and finally Blue and Red. During each selection, a nested loop is run, which cycles the color values of selected color pins. Red starts at 250 where Green starts at 0\. The nested loop cycles Red to 0 while cycling Green to 250, exits the nested loop, and then proceeds to cycle Green and Blue, and finally Blue and Red.
|
||||
|
||||
## Wiring
|
||||
|
||||
The wiring for this project is fairly straight forward. The image below is from Adafruit's website and it illustrates the wiring for an Arduino. The ESP8266 wiring is fairly similar, but because it runs on 3.3 volts, I have used two regulators to convert 12 volts. I used a 5v and 3.3v regulator because the 3.3v regulator could not take 12v as an input. You could also just get a 12v to 3.3v converter but I used what I had on hand.
|
||||
|
||||
12v PSU > 5v > 3.3v > ESP8266
|
||||
|
||||
The power on the LED strip is wired straight to the positive connections on the 12v power supply.
|
||||
|
||||

|
||||
|
||||
The image below is how I have my ESP8266 wired under my desk to control my led lights. As you can see the power comes in from the top right and the output for each RGB pin is on the left where the black is the 12v.
|
||||
|
||||

|
||||
|
||||
A picture of the final setup. I have one long LED strip along the back of the desk and two smaller strips on the back of each of the monitors.
|
||||
|
||||

|
||||
261
posts/2015-12-18-temperature-sensor.md
Normal file
261
posts/2015-12-18-temperature-sensor.md
Normal file
@@ -0,0 +1,261 @@
|
||||
# Temperature Sensor on the Web
|
||||
|
||||
The temperature readings that are displayed on this site come from the ESP8266 with a DHT11 sensor attached to it. I am going to explain the steps in the entire process. I will split it up into two parts. In this post I will focus on programming the ESP8266 and how to send data to a web server.
|
||||
|
||||
* * *
|
||||
|
||||
Update: I have updated some information regarding this project. Refer to these other posts.
|
||||
|
||||
[ESP8266 temperature sensor updates and difficulties](/?post=12-29-15.html)
|
||||
[Temperatue Sensor - Server Side](/?post=1-1-2016.html)
|
||||
|
||||
For this project you will need an ESP8266 and a DHT temperature sensor. For prototyping purposes I prefer to use the [NodeMCU module](http://www.banggood.com/NodeMcu-Lua-ESP-12E-WIFI-Development-Board-p-985891.html). There are a variety of temperature sensors that you could use, but I prefer the DHT11 because it is easy to use and it is cheap! I ordered a 5 pack of them from [Banggood](http://www.banggood.com/5Pcs-KY-015-DHT11-Temperature-Humidity-Sensor-Module-For-Arduino-p-983263.html). The source code for this project can be found on [Github](https://github.com/mgerb/esp8266-HTTPTempSensor).
|
||||
|
||||
## How it works
|
||||
|
||||
When the ESP first boots up, it reads WiFi credentials from the EEPROM and tries to connect to an access point using those credentials. If no connection is made, it starts up it's own access point and runs a web server with a captive portal. This means that when anyone connects to it, it will redirect any dns request to itself, which forces anyone to the configuration page. The user can connect to the access point and enter in the ssid, password, and preferred sensor name. This information will be saved into EEPROM and the ESP will then reboot and start sending sensor data to the server.
|
||||
|
||||

|
||||
|
||||
## ESP8266 File System
|
||||
|
||||
To run the web server, I used the file system library within the arduino ESP library. This is how I store the web content in flash on the chip. It allows me to modify all of the necessary web files without having to deal with sending them as strings from the arduino code.
|
||||
|
||||
To use the file system, you must download the tool [here](https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.1.3/ESP8266FS-0.1.3.zip) to upload your files to the ESP. Once downloaded, store it in a tools folder in the arduino folder (path "/Arduino/tools/ESP8266FS/tool/esp8266fs.jar"). Now when you create a new sketch go to the sketch folder and create a "data" folder. To upload data to this folder select "Tools > ESP8266 Sketch Data Upload" and the files will be uploaded to the ESP and will be ready to use within the program. More information on the ESP8266 file system can be found [here](http://esp8266.github.io/Arduino/versions/2.0.0/doc/filesystem.html).
|
||||
|
||||
## Sending data to the server
|
||||
|
||||
There are many ways to send the data to a server, but I implemented data transfer with a simple get request. I chose this route because it is extremely simple to create a REST API in Node.js. I will cover this in a nother post. If you are unfamiliar with a get request, it is a way a web server can receive a request, and also parameters within that request. In this case, I send temperature, humidity, location, and a key as parameters in the request.
|
||||
|
||||
If this were a full production application, this would not be the ideal way to handle data transfer to a server because it is not encrypted. A better practice would be to implement this using another TCP transfer protocol. In my case, it would be better to send a POST request over SSL, but I have not looked into that for this project yet as the method I am currently using seems to work just fine.
|
||||
|
||||
## Code
|
||||
|
||||
```arduino
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <EEPROM.h>
|
||||
#include <FS.h>
|
||||
#include <DHT.h>
|
||||
|
||||
DHT dht(5, DHT11);
|
||||
|
||||
char ssid[32] = "";
|
||||
char password[32] = "";
|
||||
char sensorName[32] = "";
|
||||
|
||||
//key used by web server to prevent unnecessary http requests
|
||||
const String server_password = "";
|
||||
|
||||
const int httpPort = 80;
|
||||
const char* host = "162.243.16.83";
|
||||
|
||||
boolean connected;
|
||||
|
||||
// DNS server
|
||||
const byte DNS_PORT = 53;
|
||||
|
||||
// Web server
|
||||
ESP8266WebServer server(80);
|
||||
DNSServer dnsServer;
|
||||
WiFiClient client;
|
||||
|
||||
/* Soft AP network parameters */
|
||||
IPAddress apIP(192, 168, 1, 1);
|
||||
IPAddress netMsk(255, 255, 255, 0);
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
|
||||
delay(1000);
|
||||
|
||||
loadCredentials();
|
||||
|
||||
//try to connect to access point
|
||||
WiFi.disconnect();
|
||||
WiFi.begin(ssid,password);
|
||||
|
||||
int connRes = WiFi.waitForConnectResult();
|
||||
Serial.print ( "connRes: " );
|
||||
Serial.println ( connRes );
|
||||
|
||||
Serial.println("Connecting");
|
||||
|
||||
for (int i = 0; WiFi.status() != WL_CONNECTED && i <10; i++){
|
||||
Serial.print(".");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//if connected skip setting up access point
|
||||
if(WiFi.status() != WL_CONNECTED){
|
||||
connected = false;
|
||||
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||
WiFi.softAP("Sensor Config");
|
||||
|
||||
delay(500);
|
||||
|
||||
server.on("/", handleRoot);
|
||||
server.on("/config", handleConfig);
|
||||
server.on("/bootstrap.min.css", handleBootstrap);
|
||||
server.on("/style.css", handleCss);
|
||||
server.onNotFound(handleNotFound);
|
||||
|
||||
SPIFFS.begin();
|
||||
dnsServer.start(DNS_PORT, "*", apIP);
|
||||
server.begin();
|
||||
}
|
||||
else{
|
||||
connected = true;
|
||||
WiFi.mode(WIFI_STA);
|
||||
dht.begin();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//if could not connect to access point
|
||||
if (!connected){
|
||||
dnsServer.processNextRequest();
|
||||
server.handleClient();
|
||||
}
|
||||
else{
|
||||
if (!client.connect(host, httpPort)) {
|
||||
return;
|
||||
}
|
||||
|
||||
float temp = dht.readTemperature(true);
|
||||
float humidity = dht.readHumidity();
|
||||
|
||||
// We now create a URI for the request
|
||||
String url = "/temperature";
|
||||
url += "?temperature=";
|
||||
url += temp;
|
||||
url += "&humidity=";
|
||||
url += humidity;
|
||||
url += "&key=";
|
||||
url += server_password;
|
||||
url += "&location=";
|
||||
url += sensorName;
|
||||
|
||||
url.replace(" ", "+");
|
||||
|
||||
Serial.println("URL: " + url);
|
||||
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Connection: close\r\n\r\n");
|
||||
delay(100);
|
||||
|
||||
while(client.available()){
|
||||
String line = client.readStringUntil('\r');
|
||||
Serial.print("Response: " + line);
|
||||
}
|
||||
|
||||
//delay(10000);
|
||||
ESP.deepSleep(120 * 1000000, WAKE_RF_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
void handleRoot(){
|
||||
if(SPIFFS.exists("/index.html")){
|
||||
|
||||
File file = SPIFFS.open("/index.html", "r");
|
||||
|
||||
server.streamFile(file, "text/html");
|
||||
|
||||
file.close();
|
||||
}
|
||||
else{
|
||||
server.send(404, "file doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
void handleBootstrap(){
|
||||
if(SPIFFS.exists("/bootstrap.min.css")){
|
||||
|
||||
File file = SPIFFS.open("/bootstrap.min.css", "r");
|
||||
|
||||
server.streamFile(file, "text/css");
|
||||
|
||||
file.close();
|
||||
}
|
||||
else{
|
||||
server.send(404, "file doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
void handleConfig(){
|
||||
|
||||
if (server.arg("password") != "" && server.arg("ssid") != "" && server.arg("name") != ""){
|
||||
|
||||
|
||||
server.arg("ssid").toCharArray(ssid, sizeof(ssid) -1);
|
||||
server.arg("password").toCharArray(password, sizeof(password) -1);
|
||||
server.arg("name").toCharArray(sensorName, sizeof(sensorName) -1);
|
||||
|
||||
saveConfig();
|
||||
|
||||
server.send(200, "text/html", "Config successful. Rebooting");
|
||||
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
server.send(200, "text/html", "<script>window.onload = function() { window.location = \"/\"; }</script>");
|
||||
}
|
||||
|
||||
void handleCss(){
|
||||
if(SPIFFS.exists("/style.css")){
|
||||
|
||||
File file = SPIFFS.open("/style.css", "r");
|
||||
|
||||
server.streamFile(file, "text/css");
|
||||
|
||||
file.close();
|
||||
}
|
||||
else{
|
||||
server.send(404, "file doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
void handleNotFound(){
|
||||
if(SPIFFS.exists("/index.html")){
|
||||
|
||||
File file = SPIFFS.open("/index.html", "r");
|
||||
|
||||
server.streamFile(file, "text/html");
|
||||
|
||||
file.close();
|
||||
}
|
||||
else{
|
||||
server.send(404, "file doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
/** Store WLAN credentials to EEPROM */
|
||||
void saveConfig() {
|
||||
EEPROM.begin(512);
|
||||
EEPROM.put(0, ssid);
|
||||
EEPROM.put(0+sizeof(ssid), password);
|
||||
EEPROM.put(0+sizeof(ssid)+sizeof(password), sensorName);
|
||||
EEPROM.commit();
|
||||
EEPROM.end();
|
||||
}
|
||||
|
||||
void loadCredentials() {
|
||||
EEPROM.begin(512);
|
||||
EEPROM.get(0, ssid);
|
||||
EEPROM.get(0+sizeof(ssid), password);
|
||||
EEPROM.get(0+sizeof(ssid)+sizeof(password), sensorName);
|
||||
EEPROM.end();
|
||||
|
||||
Serial.println("Recovered credentials:");
|
||||
Serial.println(ssid);
|
||||
Serial.println(password);
|
||||
Serial.println(sensorName);
|
||||
}
|
||||
```
|
||||
45
posts/2015-12-29-esp8266-updates.md
Normal file
45
posts/2015-12-29-esp8266-updates.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# ESP8266 temperature sensor updates and difficulties
|
||||
|
||||
I'm working on setting up new sensors now that I have been developing the back end of my website to display sensor information. Throughout this process I made updates to the current code for the project. As I continue to make progress I am overcoming obstacles as they show up.
|
||||
|
||||
* * *
|
||||
|
||||
I changed the way that the ESP8266 sends web pages to the user via HTTP requests. Previously I made use of the file system in the ESP8266, but I changed the way I did this because I noticed that it was a bit slow handling all the requests, especially because I used bootstrap to make the user interface look pretty. Although I cut down the bootstrap to only the pieces that I needed, it was still slower than I wanted.
|
||||
|
||||
I decided to not use the file system and handle the html pages within header files. I found a fairly nice way of doing this. To do this, declare a new character array, store it in flash memory with "PROGMEM", and use the raw string literal functionality of C to escape all characters in a string as show below. This is not quite as nice a dealing with an HTML file in memory, but it is easier because you do not have to upload the files to the file system every time, which takes a good amount of time.
|
||||
|
||||
`const char page_html[] PROGMEM = R"=====(/*insert html here*/)=====";`
|
||||
|
||||
This newly created page can now be sent back to the user upon an HTTP request.
|
||||
|
||||
`server.send(200, "text/html", page_html);`
|
||||
|
||||
There were a few other updates that I made. I realized that if the access point the ESP was connected to goes down, it would not try to reconnect. It will now check if it is connected to the access point every time it tries to take a temperature reading and send data. If it is not connected to the access point it will reboot. Now that it reboots, if it still cannot connect to the access point it will be stuck in config mode. I fixed this by creating a timeout. If it has been sitting in config mode for 10 minutes the device will reboot.
|
||||
|
||||
These example are show below. Keep in mind that this is not the entire program, but just the new functionality that I mentioned. The source code for the project can be found [here](https://github.com/mgerb/esp8266-HTTPTempSensor/tree/working).
|
||||
|
||||
## Problems flashing the ESP
|
||||
|
||||
I previously used the ESP-07, but recently got some new ESP-12e's because of the higher flash size. I thought this would be great if I was going to make use of the file system. After spending hours and hours trying to flash these chips, I came to the conclusion that I need a better serial to USB programmer. The current one that I use came from China and was very cheap.
|
||||
|
||||
With the new version of ESP Arduino software (2.0.0), you get the option of flashing with the ck mode. This requires GPI0 > DHT and RESET > RST. My FTDI programmer did not have an RTS pin, but rather a CTS. I found that I could flash one of my chips with this and the other I could not. After doing some research I found that it may be a problem with my Mac. Unfortunately my Ubuntu image that I usually dual boot with acted up and would not boot. This left me without any other operating system to try at the time.
|
||||
|
||||

|
||||
|
||||
Because I was experiencing problems flashing with the new ESP8266 Arduino software, I reverted to an older version (1.6.5). In this version I was able to put GPI0 > Ground and start the ESP8266 in flash mode. This is the part where I realized I have a bad FTDI programmer. When I flash the device, it will get stuck every once in awhile. I then have to unplug everything and try again. I then tried a different programmer and it was able to work every time.
|
||||
|
||||
After a good amount of frustration I was able to get my ESP8266 flashed with my new program and I got another temperature sensor set up. Here is the wiring that I used in the sensor. Keep in mind the DHT11 sensors that I used had a 10k resistor built into them.
|
||||
|
||||
GND > GND
|
||||
|
||||
GPI15 > GND
|
||||
|
||||
VCC > 3.3v
|
||||
|
||||
EN (CH_PD) > 3.3v
|
||||
|
||||
GPIO5 > Sensor Data
|
||||
|
||||
The sensor VCC and Ground then were hooked up accordingly. I used an 800ma 3.3v regulator to power everything and it is working fine.
|
||||
|
||||

|
||||
Reference in New Issue
Block a user