{"id":165,"date":"2018-05-21T16:26:15","date_gmt":"2018-05-21T14:26:15","guid":{"rendered":"https:\/\/dev.drun.net\/?p=165"},"modified":"2018-05-21T16:26:15","modified_gmt":"2018-05-21T14:26:15","slug":"measuring-temperature-humidity-pressure-esp8266","status":"publish","type":"post","link":"https:\/\/dev.krasi.net\/?p=165","title":{"rendered":"Measuring temperature, humidity, pressure with ESP8266, BMP180\/BME280 on a rechargeable battery"},"content":{"rendered":"<p>I recently started playing with ESP8266 and really like it. So I decided to make a simple OpenSenseMap temperature and pressure ( and humidity with BME280 ) stand-alone device. The idea was to have it run off battery for a long period of time and if needed, to charge it via solar panel(s).<\/p>\n<p>I decided to go with <a href=\"https:\/\/www.elecrow.com\/download\/ESP-12S_User_Manual.pdf\">ESP-12S<\/a>, which is bare-bone ESP and does not have usb input or any other schematics like Wemos D1 or similar. That&#8217;s the cheapest option available on E-Bay, AliExpress and similar sites. However, the main reason why I decided to go with it is, because I wanted to add it to a printed circuit board.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-170 size-medium aligncenter\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2204-300x200.jpg\" alt=\"\" width=\"300\" height=\"200\" \/><\/p>\n<p>When I started playing, I had no appropriate way to program it, so I made myself a &#8220;programmer&#8221; for my ESPs :). Very rough, but it works. I used schematics from <a href=\"http:\/\/www.instructables.com\/id\/ESP-12F-ESP8266-Module-Minimal-Breadboard-for-Flas\/\">this Instructable<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-172 aligncenter\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2206-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Here is how my first prototype version looks like ( worked for few weeks without problems so far):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-168 aligncenter\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2199-1024x683.jpg\" alt=\"\" width=\"960\" height=\"640\" \/><\/p>\n<p>Unfortunately I don&#8217;t have the schematics for it, but the attached one is pretty similar &#8211; it has one CLR button more, which is used when resetting device &#8211; if held while resetting, the device won&#8217;t go to deep sleep, but run a web server instead. If you hold it, press reset and keep CLR for 5 to 10 seconds pressed, the wi-fi configuration will be wiped and a Soft AP will be started. If you keep it for 10+ seconds pressed, the entire configuration will be cleared up.<\/p>\n<p>Here is the schematic I&#8217;ve made, which works pretty well:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-173\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-14.54.43-1024x506.png\" alt=\"\" width=\"960\" height=\"474\" \/><\/p>\n<p>I&#8217;ve used the following parts:<\/p>\n<ul>\n<li>ESP-12F or ESP-12S. <a href=\"https:\/\/www.aliexpress.com\/item\/MCIGICM-ESP-12F-ESP-12E-upgrade-ESP8266-Remote-Serial-Port-WIFI-Wireless-Module-ESP8266-esp12-4M\/32864723540.html\">Bought it from AliExpress<\/a>.<\/li>\n<li>10kOhm resistor for pull-up ( 6 x )<\/li>\n<li>Omron switch <a href=\"https:\/\/eu.mouser.com\/datasheet\/2\/307\/en-b3f-13826.pdf\">B3F-1000<\/a><\/li>\n<li>MA04-1 4 pin header. Had some lying around, so I reused them. You can use any kind of connector here, it&#8217;s for programming only.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-175\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-14.58.56.png\" alt=\"\" width=\"175\" height=\"104\" \/><\/li>\n<li>MicroUSB battery charger with protection TP4056. <a href=\"https:\/\/www.aliexpress.com\/item\/Automatic-Protection-2PCS-Micro-USB-5V-1A-18650-TP4056-Lithium-Battery-Charger-Module-Charging-Board-With\/32216803000.html\">Bought it from AliExpress<\/a>.<\/li>\n<li>BME280 ( or BMP180 &#8211; the pinout is similar. BMP180 is cheaper, but does not support humidity )<\/li>\n<li>100n capacitor between Vcc and GND.<\/li>\n<li>Terminal blocks (with screws) for power (battery) and solar &#8211; AK500\/2-H &#8211; pretty standard and can be found anywhere. I bought it from local electronics store. You can use any, but the important thing is that the pitch is 5.0 mm. My variant is\u00a0<a href=\"https:\/\/store.comet.bg\/en\/Catalogue\/Product\/48500\/\">DG301-5.0-02P<\/a> ( two pin version ).<\/li>\n<\/ul>\n<p>Ultimately, I&#8217;ve made also a PCB with the free version of Eagle ( as it fit perfectly into the limits ).<\/p>\n<p>Here is the zip file with schematics, pcb and the custom library for the power connector ( I just made it show + and &#8211; instead of 1 and 2 ) &#8211; <a href=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/ESP12S-measure-v1.zip\">ESP12S-measure-v1<\/a><\/p>\n<p>And here is how it looks ready with parts assembled:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-178\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2203-1-1024x683.jpg\" alt=\"\" width=\"960\" height=\"640\" \/><\/p>\n<p>I&#8217;ve fitted it into a black enclosure ( cutouts match it perfectly ). The enclosure&#8217;s specifications are <a href=\"https:\/\/github.com\/kkazakov\/esp8266-iot-sensor-fw\/blob\/master\/ESP12S-measure-v1\/G1068%20Rev%20B.PDF\">here<\/a>. I bought it <a href=\"https:\/\/store.comet.bg\/Catalogue\/Product\/16855\/\">from here<\/a>, but should be possible to find it anywhere.<\/p>\n<p>According to the schematics, CLR is connected to GPIO4 (pin 6). However, I think there&#8217;s a mistake in the Eagle part for ESP-12, and CLR is actually connected to GPIO5 (pin 5). That&#8217;s not a problem at all, as it&#8217;s easily configured in software.<\/p>\n<p>Another minor thing is that SCL and SDA seems to be inverted as it did not initially discover the BME280. However, I&#8217;m too lazy to look into that and simply switched it like this:<\/p>\n<pre>Wire.begin(2, 0);<\/pre>\n<p>Lazy, I know \ud83d\ude42 But it works and I don&#8217;t bother anymore.<\/p>\n<p>Here is a<a href=\"https:\/\/gitlab.com\/kkazakov\/esp8266-iot-sensor-fw\"> Gitlab link<\/a> with complete source. Have in mind, that I can update it so it might not work properly always, but I&#8217;ll try to keep it working.<\/p>\n<p>For uploading the code, I&#8217;m using Atom + PlatformIO, as it fits best.<\/p>\n<p>Press FLASH button and then press Upload button. When &#8220;Uploading &#8230;&#8221; appears, press and release the RESET button. Then you can depress FLASH.<\/p>\n<p>For connection, you can use any USB-to-Serial dongle, just make sure you have the right drivers and it&#8217;s discoverable. You can check <a href=\"https:\/\/dev.drun.net\/2017\/03\/01\/playing-with-hc-12-wireless-transmitter-receiver\/\">this post for more details<\/a>.<\/p>\n<p>Remember to upload also the SPIFFS file system. You can do it when you open terminal window in Atom:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-179\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-15.22.29.png\" alt=\"\" width=\"43\" height=\"40\" \/><\/p>\n<p>and type:<\/p>\n<pre>pio run --target uploadfs<\/pre>\n<p>Of course, you need to be in Flash mode ( check above ) in order to upload it.<\/p>\n<p>Once the schematic + SPIFFS data are uploaded, you can press RESET and monitor the serial output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-180\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-15.24.06.png\" alt=\"\" width=\"45\" height=\"37\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Initially, a Soft Access Point will be created ( <strong>ESP_ap<\/strong> ) without password. Connect to it and then open <a href=\"http:\/\/192.168.4.1\">http:\/\/192.168.4.1<\/a> in your browser to configure it.<\/p>\n<p>You will see a page like this. There are some (small) bugs, but I&#8217;ll sort them out.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-181\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-16.20.19.png\" alt=\"\" width=\"906\" height=\"536\" \/><\/p>\n<p>Configure the SSID from this page and connect to it. Actually it just saves it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-182\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-16.20.28.png\" alt=\"\" width=\"906\" height=\"492\" \/><\/p>\n<p>Go to next page &#8211; OpenSenseMap and configure your sensor ids:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-183\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-21-at-16.20.44.png\" alt=\"\" width=\"906\" height=\"704\" \/><\/p>\n<p>You need to go to <a href=\"https:\/\/opensensemap.org\/account\">OpenSenseMap<\/a> and register new SenseBox. You can then add Temperature, Humidity, Pressure &#8211; whichever you need to monitor. Note their IDs and fill them here. Press &#8220;Save configuration&#8221;.<\/p>\n<p>Now you can Restart the ESP via the top right menu or with RST button.<\/p>\n<p>If you missed the OpenSenseMap configuration or made some mistakes, using CLR button you can do several things:<\/p>\n<ul>\n<li>Start web server, no deep sleep mode:Press CLR button,\u00a0press and release FLASH,\u00a0 hold CLR for about 2 seconds, then release it.<\/li>\n<li>Reset Wi-Fi hotspot configuration ( will default to SoftAP\u00a0<strong>ESP_ap<\/strong> without password ):Press CLR button,\u00a0press and release FLASH,\u00a0 hold CLR for about 5-6 seconds, then release it. ESP will self-reset afterwards.<\/li>\n<li>Reset everything:Press CLR button,\u00a0press and release FLASH,\u00a0 hold CLR for about 10-15 seconds, then release it. ESP will self-reset afterwards.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Check initially in the console and you should be able to see something like this:<\/p>\n<pre>Sensor Station 0.0.2 (kkazakov@gmail.com)\nRecovered credentials:\nwifiAPName\n********\nRecovered OSM settings:\n5xxxxxxxxxxxxxxxxxxxxxx1\n5xxxxxxxxxxxxxxxxxxxxxx2\n5xxxxxxxxxxxxxxxxxxxxxx3\n5xxxxxxxxxxxxxxxxxxxxxx4\nConnect requested\nConnecting as wifi client...\nconnRes: 3\nStatus: 3\n\n\nConnected to wifiAPName\nIP address: 192.168.88.21\nT=25.30 *C, P=95495.73 Pa, H=45.35 %, A=26139.45 m\nBME sensor reading, posting to OpenSenseMap ...\n done.\nGoing into deep sleep<\/pre>\n<p>Then you should be able to see your readings on your box&#8217;s opensensemap address ( e.g. for mine: <a href=\"https:\/\/opensensemap.org\/explore\/5b006b6d223bd80019002e02\">https:\/\/opensensemap.org\/explore\/5b006b6d223bd80019002e02<\/a>)<\/p>\n<p>Note; I haven&#8217;t yet tested how much it lasts with the battery, but I will do so. My prototype station lasts 3 weeks so far without showing any sign of stopping, but it&#8217;s powered by 2 x 6000 MAh 18650 batteries ( which is plenty ).<\/p>\n<p>However, if you power it by smaller battery, it may last few months instead of 1-2 years. I&#8217;m yet to properly calculate that \ud83d\ude42<\/p>\n<p>The box:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-184\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2209-300x200.jpg\" alt=\"\" width=\"300\" height=\"200\" \/><\/p>\n<p>I made a hole near the temperature sensor:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-185\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2211-300x200.jpg\" alt=\"\" width=\"300\" height=\"200\" \/><\/p>\n<p>And then inside it barely fits with the battery, but it does \ud83d\ude42<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-186\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2018\/05\/DSCF2212-300x200.jpg\" alt=\"\" width=\"300\" height=\"200\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>I hope you enjoyed it. As always &#8211; I might missed something, you can ask in the comments if there&#8217;s something unclear.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently started playing with ESP8266 and really like it. So I decided to make a simple OpenSenseMap temperature and pressure ( and humidity with BME280 ) stand-alone device. The idea was to have it run off battery for a long period of time and if needed, to charge it via solar panel(s). I decided to go with ESP-12S, which is bare-bone ESP and does not have usb input or any other schematics like Wemos D1 or similar. That&#8217;s the cheapest option available on E-Bay, AliExpress and similar sites. However, the main reason why I decided to go with it is, because I wanted to add it to a printed circuit board. When I started playing, I had no appropriate way to program it, so I made myself a &#8220;programmer&#8221; for my ESPs :). Very rough, but it works. I used schematics from this Instructable. &nbsp; Here is how my first prototype version looks like ( worked for few weeks without problems so far): Unfortunately I don&#8217;t have the schematics for it, but the attached one is pretty similar &#8211; it has one CLR button more, which is used when resetting device &#8211; if held while resetting, the device won&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":169,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[8,9,11,13],"class_list":["post-165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hardware","tag-bme280","tag-bmp180","tag-esp12s","tag-esp8266"],"_links":{"self":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":0,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}