1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-09 01:12:52 +00:00
Files
mywebsite/New Folder/2015-12-29-esp8266-updates.html

73 lines
4.6 KiB
HTML

<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>