tag:blogger.com,1999:blog-74345529208865042882024-02-07T18:02:55.063+02:00TimpramistStuff I do. Programming, electronics, woodworking.Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-7434552920886504288.post-10206260578432756632020-06-11T12:01:00.000+03:002020-06-11T12:01:00.848+03:00Wooden handle for Rok espresso machineThe handle for our Rok espresso machine started to crack, decided it was too much work to find out how to order a new one, better make one myself. There was some apple tree that seemed like good choice.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEHl8IKk6HFPMfEN6iX6Nv6gF2ulwm1psTReYOMTDWg0oarVe7k7ob9ngVvx1Max-yqLu0_cM3sEu2B1avntidxw5YbOrzMg8ZCQsgqodFxijj91WjugtlFwTVIF39_CX9SBNDIQcXAvI/s1600/puut.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="750" data-original-width="563" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEHl8IKk6HFPMfEN6iX6Nv6gF2ulwm1psTReYOMTDWg0oarVe7k7ob9ngVvx1Max-yqLu0_cM3sEu2B1avntidxw5YbOrzMg8ZCQsgqodFxijj91WjugtlFwTVIF39_CX9SBNDIQcXAvI/s320/puut.jpg" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_X65ZUTlwTLs7ZUPdhSbC5ZjeX6vWx4pdLWj8844POOYduMjc1_gkEgY326_tgG8L8kMMMM6xRC65GVBwD_SX22yciysTf6uKDmaBwbsIkUxPrJwQk9gFi3cdXXqWNEA_qaZvyFjSnsM/s1600/sorvissa.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="750" data-original-width="1000" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_X65ZUTlwTLs7ZUPdhSbC5ZjeX6vWx4pdLWj8844POOYduMjc1_gkEgY326_tgG8L8kMMMM6xRC65GVBwD_SX22yciysTf6uKDmaBwbsIkUxPrJwQk9gFi3cdXXqWNEA_qaZvyFjSnsM/s320/sorvissa.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Finished the handle with some oilwax, only one coat. Might put a few coats more in the future, we'll see how it holds.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7iPYuOEpY0SYABPAjJsGrTdjTyhoeQEmYBwZ5dTv7UowsA3h69wBjr5jt3eY8JLCMnGOFGwYOHPu-NRxyNVGTGvGhV89ZTvX7oSSVk3DBR-gWvMLnwqVp1gkMFM1eUXuN8dk2t0YH838/s1600/valmis.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1000" data-original-width="745" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7iPYuOEpY0SYABPAjJsGrTdjTyhoeQEmYBwZ5dTv7UowsA3h69wBjr5jt3eY8JLCMnGOFGwYOHPu-NRxyNVGTGvGhV89ZTvX7oSSVk3DBR-gWvMLnwqVp1gkMFM1eUXuN8dk2t0YH838/s640/valmis.jpg" width="476" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-19151570137149500502019-12-11T22:45:00.000+02:002019-12-11T22:45:55.721+02:00Kona Ute head tube attached front rackI bought a Kona Ute this fall, I like it, but we have two kids and they take all the space in the back so I needed some kind of front rack. I had previously had a front rack that attached to the front fork but found it cumbersome as it added to the mass that had to be turned when steering. So I wanted a rack that would attached to the frame. After some digging I couldn't find one, so I decided I would make one myself.<br />
<br />
Kona Ute doesn't really have any good place for attaching a front rack to the frame, so I decided to bolt it to the head tube with two u-bolts. Luckily I had the old fork mounted rack still, so I only needed to build something to hold it in place. And the old rack was aluminium so it weights less.<br />
<br />
Didn't take any pictures while building it, but it was just basically cutting some pieces and then welding them together.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJcYs6KBXt6kHL8lA1gDFKtaET6tV0C8u8shb-Vi9pGhPNK9jbQVGCMeys9IFYQSn_6OYHsg35mg_RUF_B3RI49JtC_nWfIxo2wB9e_k8NeU6Vf4cInfyWYTXrRp-vTTHeL3Myccb8g9Q/s1600/20191201_105202.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJcYs6KBXt6kHL8lA1gDFKtaET6tV0C8u8shb-Vi9pGhPNK9jbQVGCMeys9IFYQSn_6OYHsg35mg_RUF_B3RI49JtC_nWfIxo2wB9e_k8NeU6Vf4cInfyWYTXrRp-vTTHeL3Myccb8g9Q/s320/20191201_105202.jpg" width="240" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4HwT9y8GDZQsakdBgUqwbrR6AY_uiyS59KSMnIP-Rh-QV23i2l-T-wV2pumHomuAhzz4GjFCr_p_y2On2aS3LZ7_Hfke1GLkXO8hZQ65W3m_b54NozshT0VrXiQwR0xBDAOWr4p7ySDE/s1600/20191201_105220.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4HwT9y8GDZQsakdBgUqwbrR6AY_uiyS59KSMnIP-Rh-QV23i2l-T-wV2pumHomuAhzz4GjFCr_p_y2On2aS3LZ7_Hfke1GLkXO8hZQ65W3m_b54NozshT0VrXiQwR0xBDAOWr4p7ySDE/s320/20191201_105220.jpg" width="240" /></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Finished rack, color was chosen by my daughter:)</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGdOnIIsKtizZDADXWKKOXe2-cWMN4KDowE18lGO6eXwQ-B4QG2Ja76i243g6XoCtVwbOfo6Aq_92_sz-82hjjyH9ReJ7puWsr2wEbay-7o86SJf9rr5TT4UKmS-iARf40LyP-JLNguXU/s1600/20191201_111459.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGdOnIIsKtizZDADXWKKOXe2-cWMN4KDowE18lGO6eXwQ-B4QG2Ja76i243g6XoCtVwbOfo6Aq_92_sz-82hjjyH9ReJ7puWsr2wEbay-7o86SJf9rr5TT4UKmS-iARf40LyP-JLNguXU/s320/20191201_111459.jpg" width="320" /></a></div>
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-41322880030014730482018-03-10T17:55:00.000+02:002018-03-10T17:55:45.351+02:00Solar heat, update.Some points I noticed while my <a href="http://timpramist.blogspot.fi/2017/03/solar-heat.html">solar heat system</a> was installed last spring.<br />
<br />
The glass cracked in couple of days, most likely the window frame was too tight. It was probably loose enough for normal use but in my use it heated to over 50 degrees and I'm guessing that was too much. Next time I'll make a new frame and make sure the glass is really loose in there.<br />
<br />
I'm measuring the small solar panel wrong, I should be measuring amps and not voltage. Needs to be fixed sometime in the future.<br />
<br />
ESP8266 real time clock is very inaccurate. I fixed this by ignoring the time sent and using the receiving servers time.<br />
<br />
There's not enough error handling in my code and sometimes it crashes, most likely it's in the MQTT or NTP part, network trouble probably.<br />
<br />
<div>
Using just convection didn't give that much heat so I added a fan. Currently it starts the fan when heated temperature is 20 degrees above inside temperature, when heated temperature is less than 10 degrees above room temperature then fan speed is decreased.</div>
<div>
<br /></div>
<div>
I used a standard 120 mm computer case fan I had lying around. "Case" for the fan was fabricobbeled from plastic cellular board I had salvaged from trash.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNGjZE1GLjsGOqfg34qNhu5o-mLjwGvFWW2tHah4Mrro-vIwBmCebg_VC0kGVkRv2UxZVZlxGj2ipiJHCAPLmxB7yFbtblLA7cA6wwIQsxXEVmMuxokNZX-iyErCGTmKv53UivWgF2XS4/s1600/controller_fan_update.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="656" data-original-width="1000" height="417" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNGjZE1GLjsGOqfg34qNhu5o-mLjwGvFWW2tHah4Mrro-vIwBmCebg_VC0kGVkRv2UxZVZlxGj2ipiJHCAPLmxB7yFbtblLA7cA6wwIQsxXEVmMuxokNZX-iyErCGTmKv53UivWgF2XS4/s640/controller_fan_update.jpg" width="640" /></a></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Here's an example of a sunny day, blue is outside temp (north side of the house), red is bottom of the collector, yellow is heated air and green is inside of our garage. Magenta is the "speed" of the fan, it's actually 10 bit pwm value of the ESP8266, as the fan doesn't have a pin for measuring speed, but it gives some idea on how fast the fan is running.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglJcMyZB0zSnMyp5tDFrCg4gfRwH0VgsEeSnCu2PgpZDN8nZ3nlQJVAh0gNMeLXeuaX4qjzLHynIJyEWmvCoJMDdd2o53cazn2oEwkzf6FlXMJLgB5Dnd_Mm3n1sN1g5bY2t-MD00X7bY/s1600/heater_graph_20180301.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="433" data-original-width="591" height="467" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglJcMyZB0zSnMyp5tDFrCg4gfRwH0VgsEeSnCu2PgpZDN8nZ3nlQJVAh0gNMeLXeuaX4qjzLHynIJyEWmvCoJMDdd2o53cazn2oEwkzf6FlXMJLgB5Dnd_Mm3n1sN1g5bY2t-MD00X7bY/s640/heater_graph_20180301.png" width="640" /></a></div>
<br /></div>
<div>
Updated source and Fritzing scheman can be found on github. <a href="https://github.com/mika-koivusaari/solar_air_heat_controller">https://github.com/mika-koivusaari/solar_air_heat_controller</a></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-26554014638687067012017-05-05T11:04:00.000+03:002017-05-05T11:04:34.077+03:00Weather pageI've had a weather station at our summer house for some time now, but I never got around to publishing the the data. Now I had some time and made a Spring Boot application to show the data.<br />
<br />
Station consists of 1-Wire sensors from Hobby-Boards. Temperature, barometer, wind speed and direction and rain sensors. I'll probably add a relative humidity sensor sometime so I can calculate the heat index also, currently only wind chill is calculated.<br />
<br />
Since the weather station is located at our summer house with a somewhat flaky internet connection I can't just directly save data to my home servers database. I first save it locally and then replicate it home by reading MySQL's binary log. <a href="https://github.com/mika-koivusaari/replicate_mysql_postgresql">https://github.com/mika-koivusaari/replicate_mysql_postgresql</a> Machines are connected with an SSH tunnel, I use <a href="http://www.harding.motd.ca/autossh/">autossh</a> to make sure the tunnel is always open.<br />
<br />
Weather page is <a href="https://weather.khyron.dy.fi/weather">https://weather.khyron.dy.fi/weather</a> (in finnish), and code in <a href="https://github.com/mika-koivusaari/weather">https://github.com/mika-koivusaari/weather</a>.<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-14796488525577299722017-03-17T19:21:00.000+02:002017-03-17T19:21:33.867+02:00Solar heatOur garage currently has no heating, sometimes when it's cold for a long time I put a electric heater there to make sure it doesn't go below freezing. For some time now I have thought about making a solar heater there and now I had some time to do it. One of the outside walls faces south and there is already an air intake, so that's a good starting point. I decided to only heat the incoming air and not make a full blown solar heat system with water circulation, it's cheaper and also I like to start small.<br />
<h3>
Collector</h3>
<div>
A house near us had it's windows replaced so I got one of the old ones for free. It was about the right size which reduced the work needed. Basically it's just a wooden box with polyurethane insulation I found in a dumpster, with the window put in front. Just behind the window is a tin foil paper with the paper side painted black and facing the window and sun. That way space where air heats and comes inside is covered with aluminium and there is no paint that might give out some fumes when heated. I ran out of paint so the collector isn't painted as black as it should, I'll probably paint it better in the summer as I have to take it out anyway so our garage wont heat too much. But I thought it would be good to get it installed and making heat, I can make it better later when I have some more data on how it works.</div>
<div>
<br /></div>
<div class="separator">
</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijaCEtKLvG9PLmlphzbp3p1pgx359lT7PNMtczUF8OeqThY0RtIyzmc2Wx34ThB-dCWlnx-F4SNjEX1RzxjbHtsPj0R8RCJ9JSf1ce-ILhzvu2r0u_9lAwUtR0F9JwRvFPGZTr2gxotsE/s1600/collertor_inside.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijaCEtKLvG9PLmlphzbp3p1pgx359lT7PNMtczUF8OeqThY0RtIyzmc2Wx34ThB-dCWlnx-F4SNjEX1RzxjbHtsPj0R8RCJ9JSf1ce-ILhzvu2r0u_9lAwUtR0F9JwRvFPGZTr2gxotsE/s200/collertor_inside.jpg" width="200" /></a>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQp9zVI6ziIzadPMFHbJtdIMvievE4nvwFoeS3SeJySPziRnSfyEB6Z1bfijsLokWpykCfUyA2EF_LYJ2vZsHd5dDFQ3XltoPJHr40aj07PVV0GB8qh0mCepDjptAVP2bnyAzfGWkVsqg/s1600/collector.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="194" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQp9zVI6ziIzadPMFHbJtdIMvievE4nvwFoeS3SeJySPziRnSfyEB6Z1bfijsLokWpykCfUyA2EF_LYJ2vZsHd5dDFQ3XltoPJHr40aj07PVV0GB8qh0mCepDjptAVP2bnyAzfGWkVsqg/s200/collector.jpg" width="200" /></a></div>
</div>
<h3>
Controller</h3>
<div>
The controller needs foremost to control the flap on the air intake, because there are usually no people in the garage there is no need to get fresh air all the time, so the flap can be closed when there is no heat coming. Generally when air is hotter inside the collector we open the flap more, and when it's colder we close the flap some more. For operation there's only need for two temperature sensors, heated air and inside air, but I also want to monitor cold air coming to the collector so I have three sensors. That way I can monitor how much air heats and whats the temperature difference between north and south sides of our house. There is no fan, air is only moved by convection.</div>
<div>
<br /></div>
<div>
I also had a small solar cell from a Ikea garden lamp, which I added to get some reference to compare to when I make changes to the collector or controller. I put some resistors and diodes as a load, and scaled the voltage to 0 - 1 volts with a voltage divider.<br />
<br />
All the values, temperatures, solar cell voltage and servo position are sent out with MQTT and then logged to a database so I can monitor how it works. And when I make changes I can see if it was a good or bad change.<br />
<br />
On the left the protoboard version, and on the right the final veroboard version. Power supply is just some generic psu I had lying around as I use two dc-dc converters to make the needed 5 (LCD and servo) and 3.3 (ESP8266 and DS18B20 sensors) volts.</div>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSBcJP6qf-0KtiIn7AK8O-qQujDV8y4uGt5zV4Yg28zz12s8A_2Ox-yNjKl1XKAYVf8_nN1_RB0g7FHdKYnt_lRBROnKmfr1ZbPFJCb73eZrrmUAzlsw3ORbQxlQA7-zl4AVtXLlGkLgw/s1600/protoboard.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="114" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSBcJP6qf-0KtiIn7AK8O-qQujDV8y4uGt5zV4Yg28zz12s8A_2Ox-yNjKl1XKAYVf8_nN1_RB0g7FHdKYnt_lRBROnKmfr1ZbPFJCb73eZrrmUAzlsw3ORbQxlQA7-zl4AVtXLlGkLgw/s200/protoboard.jpg" width="200" /></a>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgealjHm9OKozGF01YFvOA71nHVa6SNMwtAcEXJdnd_U44_kvBvdSvafgw3RK98-LXMl9t20uLp65hwjrjZNxjXFtbsMX1LtPMxGkghUtNJR0dl2FuRYQIUuIt-ySaU7aFd6DmVNZle0TE/s1600/controller_final.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="143" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgealjHm9OKozGF01YFvOA71nHVa6SNMwtAcEXJdnd_U44_kvBvdSvafgw3RK98-LXMl9t20uLp65hwjrjZNxjXFtbsMX1LtPMxGkghUtNJR0dl2FuRYQIUuIt-ySaU7aFd6DmVNZle0TE/s200/controller_final.jpg" width="200" /></a></div>
<br />
Controller in it's "final" installation. After one day I lowered the position of the servo some. It only opened the flap a few centimeters, now it opens some more.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjcfDwp3e-XTuM22FCJqF2M_75yuWRB7xuFrlsb_EWxF4kWQZgbUFhCexJVZQyzhZkXeWfU14cPYhOBkAliS3t-XRrpghZrLZoMItOnR0948dymNGRXT_gfb_pXt1RIxy994Sq-b_RTqc/s1600/controller_installed.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="507" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjcfDwp3e-XTuM22FCJqF2M_75yuWRB7xuFrlsb_EWxF4kWQZgbUFhCexJVZQyzhZkXeWfU14cPYhOBkAliS3t-XRrpghZrLZoMItOnR0948dymNGRXT_gfb_pXt1RIxy994Sq-b_RTqc/s640/controller_installed.jpg" width="640" /></a></div>
<br />
<br />
Source and fritzing files can be found in github <a href="https://github.com/mika-koivusaari/solar_air_heat_controller">https://github.com/mika-koivusaari/solar_air_heat_controller</a></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-35019419844401697952017-01-26T17:57:00.000+02:002017-01-26T17:57:49.457+02:00MQTT MySQL gatewayPreviously I've made a <a href="http://timpramist.blogspot.fi/2016/10/wifi-temperature-sensor.html">couple</a> of <a href="http://timpramist.blogspot.fi/search/label/you%20have%20mail">sensors</a> that send data with MQTT. Of course that data should be stored in a database. Considering that I'm probably going to make more wireless sensors that send data for example from our heating system it's best to write a easily configurable MQTT to database gateway. This gateway should also be able to send new values from database to MQTT nodes for displaying, as some data is gathered in other ways and inserted directly to db, for example <a href="http://owfs.org/">OWFS</a>(1-wire) or homegrown <a href="http://timpramist.blogspot.fi/2016/06/arduino-counter.html">pulse counters</a>.<br />
<br />
So the basic functionality would be:<br />
<ul>
<li>Recieve data from MQTT, process and save it to MySQL</li>
<li>Follow MySQL binlog and send saved data to MQTT</li>
</ul>
<div>
For input I need to have a table that stores:<br />
<ul>
<li>Subscribed topic.</li>
<li>How to get raw sensorid from topic, maybe regexp.</li>
<li>How to parse data from message.</li>
<li>Small script that processes the data so it's ready to store.</li>
</ul>
<div>
And a second table that's used to convert raw sensorid's to db sensorid's:</div>
<div>
<ul>
<li>Rawid</li>
<li>Sensorid</li>
</ul>
</div>
<div>
For output I need a table that stores:</div>
<div>
<ul>
<li>Sensorid</li>
<li>Topic to push data to</li>
<li>How to process data before sending</li>
</ul>
<div>
There are still some features to implement, like outputting data from db to MQTT, need to think how this should be done with some kind of plugin system, MySql will probably use binlog to read data, but other databases have other mechanisms.<br />
<br />
There are depencies for <a href="https://pypi.python.org/pypi/paho-mqtt/">Paho-MQTT client</a>, <a href="https://pypi.python.org/pypi/pep3143daemon">pep3143daemon</a> and <a href="http://www.sqlalchemy.org/">SQLAlchemy</a>. More detailed dependencies in requirements.txt<br />
<br />
Code in GitHub <a href="https://github.com/mika-koivusaari/mqtt_db_gateway">https://github.com/mika-koivusaari/mqtt_db_gateway</a>.<br />
<br /></div>
</div>
</div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-55063765223610510492017-01-17T15:02:00.000+02:002017-01-17T15:02:38.234+02:00Wooden urnWe had a death in the family and I wanted to make an urn for the ashes, before they are scattered.<br />
<br />
For material I used birch and heat treated birch. I wanted to make the sides at an angle, and I found a nice calculator for <a href="http://jansson.us/jcompound.html">compound miter angles</a>. Sides are only at a 5 degree angle so the bevel is almost 45 degrees. Before I sawed bevels I routed a slot for bottom with my old <a href="http://personal.inet.fi/koti/mika.koivusaari/omat_tyokalut/peili_jigi/index.html">adjustable jig</a>(in finnish).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhplxCGcWBZzKb22BNhYptPwrjzlT5Ta2KbuhbkmL4rJQo97GIMExAd0Blk1YywLbGeqy-bQHPcIKfNscSas7x-ejkesdimP3D2RqCnDnVfbJwUCaG_UsfSo5hXCcmIwEscPLo7wl47md4/s1600/jig_for_tilt_routing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhplxCGcWBZzKb22BNhYptPwrjzlT5Ta2KbuhbkmL4rJQo97GIMExAd0Blk1YywLbGeqy-bQHPcIKfNscSas7x-ejkesdimP3D2RqCnDnVfbJwUCaG_UsfSo5hXCcmIwEscPLo7wl47md4/s320/jig_for_tilt_routing.jpg" width="320" /></a></div>
<div>
<br /></div>
For the 5 degree angle I made a jig and tilted the saw blade for bevel.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVEQfo_c7wD_86mvdH3aE4GADdbUzI8dPi-GAEJUXWUNQiaSlAb1MCVhTkixA3CVLne3zLm7O5VP3cALgtJBzOwsVDsBVXReEz8PSfIbqLB-yxNsXoy8lH34CWUU6uU6EyiYumQmu0OIM/s1600/jig.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVEQfo_c7wD_86mvdH3aE4GADdbUzI8dPi-GAEJUXWUNQiaSlAb1MCVhTkixA3CVLne3zLm7O5VP3cALgtJBzOwsVDsBVXReEz8PSfIbqLB-yxNsXoy8lH34CWUU6uU6EyiYumQmu0OIM/s320/jig.jpg" width="320" /></a></div>
<br />
<br />
<br />
<br />
Top was glued from four pieces, and one piece in the bottom to hold it in place, and cut to size with bottom. Finished with wax.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPtVZOcSp-gTLb1mbcDEyTMxyaNzd4cmPRWs6N79KO7B7BWTbcEOJMrRJ8bf27InhM7sZCIIkWdsQ6yLG2UcLS3DhO0pJzrepph7aswW1K6KtV77eBt5CgwXyErgg7FlDfi7n3irzYZ_4/s1600/finished.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPtVZOcSp-gTLb1mbcDEyTMxyaNzd4cmPRWs6N79KO7B7BWTbcEOJMrRJ8bf27InhM7sZCIIkWdsQ6yLG2UcLS3DhO0pJzrepph7aswW1K6KtV77eBt5CgwXyErgg7FlDfi7n3irzYZ_4/s320/finished.jpg" width="283" /></a></div>
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-63780375015180531282016-11-30T22:25:00.000+02:002016-11-30T22:25:37.072+02:00Magic ice wandSanta Claus delegated manufacturing of one magic ice wand for me. After looking through my junk pile I found:<br />
<br />
<ul>
<li>Clear plastic sheet</li>
<li>Blue led + resistor</li>
<li>One 18650 cell</li>
<li>Metal pipe</li>
<li>Push button</li>
</ul>
<div>
In addition I had to order one cell 18650 charger module with micro usb input.</div>
<div>
<br /></div>
<div>
Metal pipe functions as the handle, and plastic sheet as the ice part. I had to glue three sheets together with super glue to get the right thickness. Then I just soldered all together, tested it and added some hot glue and tape. Plastic was formed to icicle with a belt sander.<br />
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhub0V-YnXMxj1Et-AfIGlvuZLdko6mK_fAR2ygySawpYQOcXVECq-lA06o_sqHH8EYHBmqHdsPmcPjMYqB7rinbzR1f2bvckc8Uc3r25hfzJ5ujsl-I2GKJP1bpCnWp8TRnGUgSVVYjrU/s1600/parts.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhub0V-YnXMxj1Et-AfIGlvuZLdko6mK_fAR2ygySawpYQOcXVECq-lA06o_sqHH8EYHBmqHdsPmcPjMYqB7rinbzR1f2bvckc8Uc3r25hfzJ5ujsl-I2GKJP1bpCnWp8TRnGUgSVVYjrU/s320/parts.jpg" width="320" /></a></div>
</div>
<div>
<br /></div>
<div>
Metal pipe was painted pink and then I put everything together with hot glue.</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzxkg7nT49w7Rq5_quh6QAl2Zld4BQBFXoi8nMV2_0jecm_sM1ZocOKQ_1iYniuvyrjX7-inMh2ZqHLlDNiDeoy2Cuml9fCPvMI49eiZQsaKsO6bFMxDU_pgQaYBTVEVDPUX5Box05OFA/s1600/assembled.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzxkg7nT49w7Rq5_quh6QAl2Zld4BQBFXoi8nMV2_0jecm_sM1ZocOKQ_1iYniuvyrjX7-inMh2ZqHLlDNiDeoy2Cuml9fCPvMI49eiZQsaKsO6bFMxDU_pgQaYBTVEVDPUX5Box05OFA/s320/assembled.jpg" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAKhpTk5exbr579eKv6x9v8S7dNjnUIAcGNfMKBGJV1va6ToxIl4h16tNvkTCMbkiUYz_DLjIXT124oh7zF_Vc6tN7igr1NkfH66icXF3RZKSh5Ia6f2qOeVRbql_3TRggcMWim5NVZDA/s1600/glow.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAKhpTk5exbr579eKv6x9v8S7dNjnUIAcGNfMKBGJV1va6ToxIl4h16tNvkTCMbkiUYz_DLjIXT124oh7zF_Vc6tN7igr1NkfH66icXF3RZKSh5Ia6f2qOeVRbql_3TRggcMWim5NVZDA/s320/glow.jpg" width="219" /></a></div>
<br />
<br /></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-39104820897073352382016-10-28T18:56:00.001+03:002016-10-28T18:56:32.553+03:00Wifi temperature sensorI have need for some temperature sensors where I'm too lazy install cables or the need is only for a short while. I also wanted to try <a href="http://www.micropython.org/">micropython</a> on ESP8266, so why not combine the two.<br />
<br />
Installing micropython on ESP8266 is pretty simple, but somewhat time consuming the first time. Micropythons ESP8266 has good <a href="https://github.com/micropython/micropython/tree/master/esp8266">build instructions</a>. Same goes goes for the needed <a href="https://github.com/pfalcon/esp-open-sdk">esp open sdk</a>. Building the esp-open-sdk takes pretty long time, but you don't have to update it that often.<br />
<br />
What I want to do is have the eps8266 measure temperatures once a minute and then send the values with MQTT. Because I'm using DS18b20 sensors and they have a unique address I can just add that to the MQTT topic, something like /house/temperatures/1wire/285cb4ce0100009a and then have time and value in the message.<br />
<br />
Micropython has a separate <a href="https://github.com/micropython/micropython-lib">library repository</a> that has MQTT library, but trying to just import that on ESP8266 gives an error and it seems that error is because there is not enough ram to compile to source, so the only way to use it is to precompile it by copying it to modules directory before building the firmware. That way it gets precompiled and you can use just like any other python module.<br />
<br />
I'm thinking of sending the time in the message along with the value, for that I need to keep somewhat accurate time on the ESP8266. I wrote a little script to see how accurate the rtc was, and it drifted about ten minutes in five hours, so I definitely should check the time every time I wake up from deep sleep. Script can be found here <a href="https://gist.github.com/mika-koivusaari/90febd8a101412bf0e5c71d9c736e855">https://gist.github.com/mika-koivusaari/90febd8a101412bf0e5c71d9c736e855</a><br />
<br />
<div class="separator" style="clear: right; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3XnUF488LD4LJkT-qk-nE2nZoKpe8N8uxF9SBIarsz9SYvwph3SHVnCg5uBQsOn_zfoU0rcbgFZzwLpBl5cqqYUmvQJ3lmKNx63nUsitf5pq6enqAvn9ZfK0AJEqtsFZmoWMeui919uw/s1600/ds18b20_reader_bb.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3XnUF488LD4LJkT-qk-nE2nZoKpe8N8uxF9SBIarsz9SYvwph3SHVnCg5uBQsOn_zfoU0rcbgFZzwLpBl5cqqYUmvQJ3lmKNx63nUsitf5pq6enqAvn9ZfK0AJEqtsFZmoWMeui919uw/s320/ds18b20_reader_bb.jpg" width="264" /></a>
Fritzing drawing of the connections. There isn't much stuff so I just soldered it all on the board. Sensors, power and battery monitor leads are of course with connectors. I actually used a 18650 cell but didn't have a Fritzing part for that. I also used a dc - dc converter instead of a linear regulator.
</div>
<br />
<div class="separator" style="clear: both;">
</div>
<br />
Finished product, held together with heat shrink tube and hot glue:)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1ZuJ0ov4nJaI52_cOqo3QqjDJIqD80kqlk8feSazxGgD5ozh4vK-H5TC25-MZBomFFJInpClZXfcxxSO40oUXMs-Ac3i8TbWzWDGUWeWbY8PBnofnJ-exbrs3Sw3RQR01rbtH3e0dPdE/s1600/ds18b20_reader_psu.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="169" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1ZuJ0ov4nJaI52_cOqo3QqjDJIqD80kqlk8feSazxGgD5ozh4vK-H5TC25-MZBomFFJInpClZXfcxxSO40oUXMs-Ac3i8TbWzWDGUWeWbY8PBnofnJ-exbrs3Sw3RQR01rbtH3e0dPdE/s320/ds18b20_reader_psu.jpg" width="320" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY4vY-9pgcBi4Hi3o4PTJAKRIttrfArdhVnD7kGd4-UDZgDdE-6kySoLbQ5LNLJfyoWQMulbDh3KqRM8tZMwEDYaaaTmULAxcAtxB122zZyz3OSsM54PMe-GW2Q4OLN35xrnFEX5T9L8A/s1600/ds18b20_reader_esp201.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY4vY-9pgcBi4Hi3o4PTJAKRIttrfArdhVnD7kGd4-UDZgDdE-6kySoLbQ5LNLJfyoWQMulbDh3KqRM8tZMwEDYaaaTmULAxcAtxB122zZyz3OSsM54PMe-GW2Q4OLN35xrnFEX5T9L8A/s200/ds18b20_reader_esp201.jpg" width="182" /></a>
<br />
<br />
<br />
Code is pretty simple.<br />
<br />
<ul>
<li>Wake up</li>
<li>Check if stop pin is down</li>
<li>Make measuments (only temperature and battery voltage at this time)</li>
<li>Wait for wifi connection</li>
<li>Connect to MQTT broker</li>
<li>Send values</li>
<li>Go to deep sleep</li>
</ul>
<br />
Code and Fritzing files can be found in <a href="https://github.com/mika-koivusaari/remote_sensor">https://github.com/mika-koivusaari/remote_sensor</a>.<br />
<br />
There's probably some bugs still that I have to sort out. But for future I might add some different sensors, for example humidity. Only send measured data every x minutes and store it between sends, to conserve battery. Maybe think some more about MQTT topics so they would be logical and extendable. Some more configuration options, and a local ntp server.<br />
<br />
Next I should probably code a MySql - MQTT gateway so I can store those readings:)<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-48732234795948472292016-10-23T15:26:00.000+03:002016-10-23T15:26:57.889+03:00Trying C# and Visual StudioI have never really worked with Microsofts development tools so I wanted to try. <a href="https://www.visualstudio.com/vs/">Visual Studio</a> has a free community version that suits this purpose.<br />
<br />
After a bit of thinking I thought I could make a <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">RPN</a> calculator, a simple program but I can still get some complexity there for fun.<br />
<br />
Some points I want to try:<br />
<br />
<ul>
<li>Operators as classes, just some basic oo-programming</li>
<li>Basic operators built-in, some operators loaded dynamically from dll</li>
<li>Unit testing</li>
<li>Refactoring</li>
</ul>
<div>
Dynamic loading of classes seems pretty simple, you just get the reference to Assembly (e.g. exe or dll) and then just look filter those classes that you are interested. getOperatorsFromAssembly function in <a href="https://github.com/mika-koivusaari/rpn_calculator/blob/master/rpn_calculator/rpn_calculator/Program.cs">Program.cs</a> does the heavy lifting and is called from initOperators. Currently the only dll name is hardcoded, and a better solution would be to put all dll's in some directory and just load all of them, but I most likely won't do that.</div>
<div>
<br /></div>
<div>
Unit testing, Visual Studio can create test class stubs for a specific class, which is nice. Running tests is simple.</div>
<div>
<br /></div>
<div>
Basic refactoring, renaming and moving blocks of code to functions is straightforward.</div>
<div>
<br /></div>
<div>
Results can be found in github <a href="https://github.com/mika-koivusaari/rpn_calculator">https://github.com/mika-koivusaari/rpn_calculator</a>.</div>
<div>
<br /></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-37526527804936356592016-09-19T14:18:00.001+03:002016-09-19T14:18:21.123+03:00Measuring battery voltage with ESP8266If you run IoT devices on batteries then it would be nice to know how much capacity is left on the battery, so you can change it before the device dies. Easiest way to do this is measuring battery voltage. Esp8266 has adc, but it's only from zero to one volt. The correct way would probably be to use <a href="http://www.daycounter.com/Circuits/OpAmp-Level-Shifter/OpAmp-Level-Shifter.phtml">Non-Inverting Op-Amp Level Shifter</a>, but that would require many components and negative voltage. Easier approach is to just use voltage divider and just get the maximum voltage to acceptable range.<br />
<br />
Using a <a href="http://www.raltron.com/cust/tools/voltage_divider.asp">calculator</a> we get resistor values of 120kOhm and 39kOhm for getting 4.1 volts to 1 volt. For a low voltage of 3 volts these resistors would give 0.736 volts. So we are using 0.264 of esp8266 adc range of 0 - 1 volts. Adc is 10 bits so we have 0.264*1024=270 different values, even with some noise that should be enough for our purpose.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZG_ouFefKLc8BI1lpsCFBt2EPShFoqPkSctqPfXYDOML5l7CpAIvytQfZMSWvXnZacBnPha19A58j6WXhE4kni6LR4JbkFQEvrDM8FJulsPiWSv3qwofuqkaJKngQ2f4Vu5A0chcs_UY/s1600/esp201_measure_battery_voltage.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZG_ouFefKLc8BI1lpsCFBt2EPShFoqPkSctqPfXYDOML5l7CpAIvytQfZMSWvXnZacBnPha19A58j6WXhE4kni6LR4JbkFQEvrDM8FJulsPiWSv3qwofuqkaJKngQ2f4Vu5A0chcs_UY/s320/esp201_measure_battery_voltage.jpg" width="229" /></a></div>
<br />
<br />
I made a small lua script that reads adc every minute and then posts the result with mqtt. Then used mosquitto_sub from <a href="https://mosquitto.org/">Mosquitto</a> to subscribe to that topic and log the messages.<br />
<code>mosquitto_sub -h roope.local -t /esp/battery | while read line; do echo -n $(date -Ins); echo -e "\t$line"; done | tee esp_battery.log</code> Where roope.local is the mqtt broker machine.<br />
<br />
Measurements and calculations can be found here <a href="https://docs.google.com/spreadsheets/d/1t18V1jrTRbj8nI5lrpctb8Fs9KzmpQ9O05dR5AeF37k/edit?usp=sharing">https://docs.google.com/spreadsheets/d/1t18V1jrTRbj8nI5lrpctb8Fs9KzmpQ9O05dR5AeF37k/edit?usp=sharing</a>. Esp_battery tab has raw data and formula has cleaned up data and formula.<br />
<br />
I used google sheets linest function to calculate a function to get voltage from adc values, voltage<span style="font-family: "arial" , "sans" , sans-serif; font-size: 13px;">=</span><span style="font-family: "arial" , "sans" , sans-serif; font-size: 13px; text-align: right;">0.003539154715</span><span style="font-family: "arial" , "sans" , sans-serif; font-size: 13px;">*adc+</span><span style="font-family: "arial" , "sans" , sans-serif; font-size: 13px; text-align: right;">0.3756228338.</span><br />
<br />
<table border="1">
<tbody>
<tr>
<th>adc</th><th>voltage</th>
</tr>
<tr><td>1000</td><td>3.914777549</td></tr>
<tr><td>900</td><td>3.560862077</td></tr>
<tr><td>800</td><td>3.206946606</td></tr>
<tr><td>700</td><td>2.853031134</td></tr>
<tr><td>600</td><td>2.499115663</td></tr>
</tbody></table>
<br />
<div>
One problem for voltage divider is that it uses some power all the time. I should probably check how much that is, and if it considerably affects how long the battery will last. But for my next battery powered project, it will most likely report battery status also.</div>
<div>
<br /></div>
<div>
Code can be found here <a href="https://github.com/mika-koivusaari/check_battery">https://github.com/mika-koivusaari/check_battery</a>.</div>
<div>
<br /></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-37434606416090801632016-09-08T10:34:00.002+03:002016-09-08T10:34:48.913+03:00You have mail 2After having done the hardware for checking mail I had to make some kind of user interface to show that data. I had previously <a href="http://timpramist.blogspot.fi/2016/05/outside-temperature-and-electricity.html">used an old IPhone</a> to display temperature and power usage, so it was an easy choice to continue using it.<br />
<br />
Previously I had just used a simple php script to fetch and display data, now I wanted to try python and <a href="http://flask.pocoo.org/">Flask</a>. I used a tutorial found <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world">here</a> to get started.<br />
<br />
Code is pretty simple, temperature and electricity usage is fetched every time from database, but this page is usually only open on the extra phone that displays this data so there shouldn't be any reason to cache that data. That data is also updated to database every minute so it should be refreshed every time. Mail status is received over mqtt and it's sent only when it changes so it has to be cached.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv94lLNYtIpI226epNHZna0d6WR4qZT-7shehm4mqhGeLx1nevuOBnNGwt2ioQlB0O013aIom6_Ong065sn1uLsqx4KZjb0Axr9WIYkR8tQL5CQ11GnxaUP7sS0EBYsa_aIOWhbcMNc9g/s1600/data_display_phone.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv94lLNYtIpI226epNHZna0d6WR4qZT-7shehm4mqhGeLx1nevuOBnNGwt2ioQlB0O013aIom6_Ong065sn1uLsqx4KZjb0Axr9WIYkR8tQL5CQ11GnxaUP7sS0EBYsa_aIOWhbcMNc9g/s320/data_display_phone.jpg" width="185" /></a></div>
<br />
I also made a couple of changes to the hardware/firmware section, for the firmware I set the retain flag in the mqtt message so that when clients connect they get the last know value of mail. For the hardware I added a bigger antenna because I have some trouble with the wifi reception. Reception is still not as good as I would like, I have to think about it. Maybe second wifi ap, I'm also thinking if I should build a separate network for IoT-devices, currently there is only one wifi device, but that could easily change. I also changed the psu to one that outputs more current and has a lower quiescent current as I thought that the wifi problem might be because the ESP8266 is not getting enough current to transmit, but that didn't solve the problem. Before I had a cheap chinese buck/boost converter, and now I have <a href="https://www.pololu.com/product/2830">https://www.pololu.com/product/2830</a> which can ouput more current, but is only a buck converter and needs at least 4 volts to output 3.3 volts. So I had to replace the three aaa batteries with four aa batteries to get enough voltage.<br />
<br />
Also there is a problem with the mailbox itself:) It let's sunlight through somewhere and that's enough so we can't see if the led is on or not. I'll have to think how to put some seals there.<br />
<br />
<h3>
Future improvements</h3>
<div>
Hardware</div>
<div>
<ul>
<li>Monitor battery state.</li>
<li>Don't turn radio on on wake up, only when we need to send. <a href="https://github.com/nodemcu/nodemcu-firmware/issues/1225">NodeMCU bug</a> might prevent this currently.</li>
</ul>
<div>
Software</div>
</div>
<div>
<ul>
<li>Move temperature and electricity to mqtt also.</li>
<li>Add today's forecast.</li>
</ul>
<div>
Software can be found here <a href="https://github.com/mika-koivusaari/data_display_phone">https://github.com/mika-koivusaari/data_display_phone</a></div>
</div>
<div>
<br /></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-69551673166007489102016-08-31T18:53:00.000+03:002016-08-31T18:53:21.760+03:00Fixing the apple pressAfter almost two falls our apple press broke, threads on it wheren't that good to begin with. The rod was ok but the nut had too weak threads. First I tried to find a suitable replacement nut but the threads where some weird size, probably imperial, so I had to change the rod too.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1E5m_CQbka-F3hAp2Lzp0s369PD1_SmA5zlM-MExHUO1XShE5OY_Mq-m9Lu7eXl2zgLIs5xtatRyotqxh-ECqivrmuMp7gvFMO1FHCFxhZ2zT9-ry4tQeP1H3k8ZgqqEzsMbS-G2ffEM/s1600/apple_press_fixing.jpg" imageanchor="1" style="float: left; margin-bottom: 1em; margin-right: 0em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1E5m_CQbka-F3hAp2Lzp0s369PD1_SmA5zlM-MExHUO1XShE5OY_Mq-m9Lu7eXl2zgLIs5xtatRyotqxh-ECqivrmuMp7gvFMO1FHCFxhZ2zT9-ry4tQeP1H3k8ZgqqEzsMbS-G2ffEM/s200/apple_press_fixing.jpg" width="111" /></a>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOrpA3LqG2QFr6cJPzINSpv7-kQT-YLnhFxzSLmgDatoLDFLJbzr8YcTiyDl-JHOoIVfPqosg1biAHyEtTCcLXt-hkzeWXsjE0uMs6NGp3r8sFHzwg4qNDBb9iNwvT3mg8SiZ9YO4tNw4/s1600/apple_press_fixing2.jpg" imageanchor="1" style="float: right; margin-bottom: 1em; margin-right: 0em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOrpA3LqG2QFr6cJPzINSpv7-kQT-YLnhFxzSLmgDatoLDFLJbzr8YcTiyDl-JHOoIVfPqosg1biAHyEtTCcLXt-hkzeWXsjE0uMs6NGp3r8sFHzwg4qNDBb9iNwvT3mg8SiZ9YO4tNw4/s200/apple_press_fixing2.jpg" width="112" /></a>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsSLoknuuteFaY4GxcLo_Vjwrdk6OHBA85-RFnANAt2SruA9e6aEobtu5r3QqjSbaMKDMVKf4KomK3RfJXaEBk0eWz1npr6VV-5aWSDaOMedxOHKtAtN1kyPkw2mvpZAMWynJ2UUb72jA/s1600/apple_press_fixing3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 0em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsSLoknuuteFaY4GxcLo_Vjwrdk6OHBA85-RFnANAt2SruA9e6aEobtu5r3QqjSbaMKDMVKf4KomK3RfJXaEBk0eWz1npr6VV-5aWSDaOMedxOHKtAtN1kyPkw2mvpZAMWynJ2UUb72jA/s200/apple_press_fixing3.jpg" width="112" /></a></div>
<br />
<br />
I used a 20 mm trapezoidal thread.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/7dGeRs3KGsE/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/7dGeRs3KGsE?feature=player_embedded" width="320"></iframe></div>
<br />
After fixing it works again.<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-10656594243815962292016-08-24T07:51:00.000+03:002016-08-25T18:58:07.186+03:00Making apple juiceFall, apples are getting ripe. Time make some juice.<br />
<br />
We have several apple trees, and we know that if we just freeze slices we probably wont use them. But we do drink juice. We have tried juicers, but they tend to be meant for smaller scale, few liters maybe. Then I came across Matthias Wandel's <span style="font-family: "helvetica";">homepage and his apple cider making page</span> <a href="https://woodgears.ca/cider/">https://woodgears.ca/cider/</a>. I copied the design somewhat and came up with this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLvoupkTYi-lermDb8FfvoxsyBjIAu3r9MbieoGcXa7qI88sJiV43ZO3bx3rtviRN0cPXlwsg8Lydukt_0JD1SpuqDY3CtvDKw3dao7RBeUvm9ORcURB4tNESmj2OP5goVtgr_gugt7A8/s1600/apple_crusher.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLvoupkTYi-lermDb8FfvoxsyBjIAu3r9MbieoGcXa7qI88sJiV43ZO3bx3rtviRN0cPXlwsg8Lydukt_0JD1SpuqDY3CtvDKw3dao7RBeUvm9ORcURB4tNESmj2OP5goVtgr_gugt7A8/s400/apple_crusher.jpg" width="400" /></a></div>
<br />
It's current in prototype stage, I want to make a bigger place to put the apples, preferably so large that I can just pour a whole moving box of apples there and let it crunch away. Also a better stand would be nice. The vfd in the back is just to test different speeds, I intend to replace that motor with something a bit smaller and one phase. Video of the crusher can be found here <a href="https://youtu.be/YjaJNmqus-Y">https://youtu.be/YjaJNmqus-Y</a><br />
<br />
I haven't had time to build a press so I'm forced to use this store bought. It does it's job but could be better.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-UUHwAEYdXYOaru2BfS6ctFBsQyQHgTxKFoc83xo-nKzsy-eSTZNLp1OmqChgJvW3XgbAxwwJEBwwkNU7dFHvpLJa1KV4PMXr2IG4IBb4LU_40e9yV65dPKSUa_mwROKMK2t7D6PRHEw/s1600/apple_press.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-UUHwAEYdXYOaru2BfS6ctFBsQyQHgTxKFoc83xo-nKzsy-eSTZNLp1OmqChgJvW3XgbAxwwJEBwwkNU7dFHvpLJa1KV4PMXr2IG4IBb4LU_40e9yV65dPKSUa_mwROKMK2t7D6PRHEw/s400/apple_press.jpg" width="225" /></a></div>
<br />
Today i harvested two trees, about four moving boxes full of apples, 30 liters of juice.<br />
<br />
update: Second time, about 75 kg of apples gives about 25 litres of juice.<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-67169062822410090712016-08-09T13:30:00.000+03:002016-09-08T10:32:07.587+03:00You have mail, power usage 2Still no luck, batteries died over the weekend.<br />
<br />
One of my thoughts was that if something goes wrong, for example we don't get wifi connection, then the device just sits there sucking power. So i added a timer just after we wake up that waits for 10 seconds and then goes to sleep, 10 seconds should be plenty time to get a connection and send data.<br />
<br />
Also added was error handling to wifi and mqtt connections, if we don't get a connection we go to sleep and try again.<br />
<br />
I also added a feature that we only send messages when state changes, and we only wake up the modem when we need to send something. For this I needed a new firmware that has rtcmem module. But the master had changed SDK version and I couldn't get the new firmware to work. I tried erasing (<a href="http://nodemcu.readthedocs.io/en/latest/en/flash/#upgrading-firmware">http://nodemcu.readthedocs.io/en/latest/en/flash/#upgrading-firmware</a>) flash but still couldn't get it to work. I had to get the excellent <a href="https://hub.docker.com/r/marcelstoer/nodemcu-build/">Nodemcu-build docker image</a> and use it to build a previous version. Which worked fine. I tried using the lowest power option in deep sleep, but there seems to be some problem with it, and I couldn't get it to work <a href="https://github.com/nodemcu/nodemcu-firmware/issues/1225">https://github.com/nodemcu/nodemcu-firmware/issues/1225</a>.<br />
<br />
On thing that also was on my mind was the really small antenna that came with the Esp-201 modules. Most likely a better antenna would give less trouble. I had some old adsl-modems laying around that had built in wifi with external antennas. I salvaged an antenna from one of them, and now I get better reception.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoGCn44EQ2zkztArNJhyvPxXB8wy7G1gi9nZvjMQbb_B7VNsJx1k9Flyj9divlsCY4ED0braqzdiHIUgXdPGEiayz1Ru-oIyHZ8kT5euDPi9TxbieCRgMSS0UKfqzvWbwm-I8b4ylzkkU/s1600/you_have_mail_installed_long_antenna.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoGCn44EQ2zkztArNJhyvPxXB8wy7G1gi9nZvjMQbb_B7VNsJx1k9Flyj9divlsCY4ED0braqzdiHIUgXdPGEiayz1Ru-oIyHZ8kT5euDPi9TxbieCRgMSS0UKfqzvWbwm-I8b4ylzkkU/s320/you_have_mail_installed_long_antenna.jpg" width="178" /></a></div>
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-49864572107670263342016-08-04T22:34:00.000+03:002016-09-08T10:32:25.960+03:00You have mail, power usage.After a less than 24 hours my mail sensors died. Batteries where around 1 volt, so it had drained them pretty quickly, something had to be done.<br />
<br />
First I started to measure how many mA my circuit uses. But I was faced with a continually resetting Esp8266. At first I thought it had somehow messed the program in it's flash because of low voltage situation, but after a while of debugging I got the idea to measure the voltage, and it turns out that when measuring mA my multimeter drops the voltage from 3.3 to 3.1, and that makes the Esp8266 go crazy. Then I moved amperage measuring before the dc-dc converter. After that the circuit worked fine. There is a nice article about this issue here <a href="http://www.eevblog.com/files/uCurrentArticle.pdf">http://www.eevblog.com/files/uCurrentArticle.pdf</a><br />
<br />
The following amperage readings are before the dc to dc converter when I powered the circuit from usb at 5 volts. When Esp8266 was active the circuit drawed around 40 - 100 mA of current. In deep sleep it took about 8 mA, which was quite high. After a bit of googling I found that the power led was using significant amount of power, so I took it out. Power went down to 3.4 mA, which is still quite high. After some thinking I started looking at how much TSL257 draws current, and it was typical 1.9 mA and max 3.5 mA according to datasheet. After moving TSL257 power to gpio, so it's only on during mail check, deep sleep current is 0.5mA, which is pretty much all taken by the dc-dc converter. Which I can't do anything about, without buying a new converter, so I'll settle for this now. If aaa batteries are about 1000 mAh then they should last about 1000/0.5/24=83 days, so over two months. Which at least gives me some time to think what I will do.<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-41065025658924473732016-08-02T23:22:00.000+03:002016-09-08T10:32:54.610+03:00You have mailHave you ever wondered has the mail arrived yet? I got my ESP8266 some while ago and was wondering what to do with it. After a while I thought it would be perfect for checking if mail had arrived, and I mean the traditional physical kind with envelopes.<br />
<br />
<h4>
Hardware</h4>
I figured some kind of light gate would be good for detecting if there is something in the mailbox. At first I tried with ldr and some led's, but couldn't get it to work. Either it didn't notice the led or ambient light was enough. Probably if I had a different type of ldr with different resistance it could have worked, but I didn't. So I used a <a href="https://ams.com/kor/content/download/250427/976469/file/TSL257S_Datasheet_EN_v1.pdf">TSL257</a> that I had lying aroung, and it seems to do the trick.<br />
<br />
On the hardware side everything is simple, TSL257 connected to input pin, and a led with a transistor connected on a output pin. Because Esp8266 can only output a maximum of 12mA on it's pins I put a transistor to drive the led, so I could drive it at a higher amperage. Fritzing ESP-201 module from <a href="https://github.com/ydonnelly/ESP8266_fritzing">https://github.com/ydonnelly/ESP8266_fritzing</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCNeC2XjyCFLU8WQi3ogin7qV_I3fqKLfG0SFXUauD348ycL5qe55GyqLNmTbd1GKdglg_tjm8nZlUB7QWm2vRNUQMhsnQrE3QW7WqdIDSDafamPv3TFuEa_j-VZ7HOK26_5W0dSUJlwY/s1600/you_have_mail_fritzing_no_breadboard.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="371" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCNeC2XjyCFLU8WQi3ogin7qV_I3fqKLfG0SFXUauD348ycL5qe55GyqLNmTbd1GKdglg_tjm8nZlUB7QWm2vRNUQMhsnQrE3QW7WqdIDSDafamPv3TFuEa_j-VZ7HOK26_5W0dSUJlwY/s640/you_have_mail_fritzing_no_breadboard.png" width="640" /></a></div>
<br />
<br />
Since I use deep sleep between checks XPD has to be connected to reset pin(black wire). Resistors on top of the Esp-201 and the yellow wire are for normal boot mode, as the module doesn't have these ready.<br />
<br />
If pin2 (gpio4) is pulled low then the normal check and sleep is not done, this is so you can update lua scripts without reflashing the whole thing.<br />
<br />
For a power supply I use three aaa batteries in series and a step down converted to get the 3.3 volts that is needed.<br />
<br />
Since the circuit was so tiny I didn't use a pcb but just soldered the components together. Wires going to top right are for led and wires going bottom left are for TSL257.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbo-QAjJLgiHJKVfjRy2UnK3vSDdPUj2R0ReOtI5r8Zf-0ZDrjzCHQxmPwFhk2qUk_fKg_zzm_T1RR_NX9Cd4fQjS_KvzIVSQa4njV4OnOJzgDGEEKUWSAj5les3EqoM7z-k6SF_HtwW4/s1600/you_have_mail_device.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="304" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbo-QAjJLgiHJKVfjRy2UnK3vSDdPUj2R0ReOtI5r8Zf-0ZDrjzCHQxmPwFhk2qUk_fKg_zzm_T1RR_NX9Cd4fQjS_KvzIVSQa4njV4OnOJzgDGEEKUWSAj5les3EqoM7z-k6SF_HtwW4/s320/you_have_mail_device.jpg" width="320" /></a></div>
<br />
<br />
I used a ESP-201 module, because it has an external antenna, and it's small and cheap. Because it doesn't have a usb connector it also has slightly smaller power usage, but I have to use a separate usb to serial module for programming. At first I used cheap clone ordered from aliexpress, but kept getting errors when flashing. So I bought a different module from a local shop and it worker like a charm. Others have also had trouble with cheap usb to serial modules when flashing ESP8266 modules.<br />
<br />
Here is the device installed. Installation is not permanent, so I can better debug or change something if need be. Also we will probably get a new mailbox soon. Which would be good because our current mailbox is made from plastic and it lets light in just enough that when sun is shining it interferes. I had to tape the inside to block sun light.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm_2mx18slr1bZ_e_wwEwTpcbn47JePY2EIK8tleIzJsj_QC21YVt7BfkebkNzXlgtvg3FboEHOtbmnsl4A2UpjnaBiP2RGbE33zczpNUNYhxvf0M7-QW6UaZHwJ4yqzt3KFBh8ouWsgc/s1600/you_have_mail_installed.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm_2mx18slr1bZ_e_wwEwTpcbn47JePY2EIK8tleIzJsj_QC21YVt7BfkebkNzXlgtvg3FboEHOtbmnsl4A2UpjnaBiP2RGbE33zczpNUNYhxvf0M7-QW6UaZHwJ4yqzt3KFBh8ouWsgc/s320/you_have_mail_installed.jpg" width="304" /></a></div>
<br />
<br />
And here is the inside.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9lg7lVZHbRsr0a4u4R7BH_jN55IRNtal1TWUfDs5RuQFMFWAaR51kTTQEMJd2f1l9w1RPEWZYz4krsvkqUUsW3Fjj3y4bc0GKRS-7kWUUKUfEXtIu6LCtBXZDB4vmwCHEfXkC6EITfnM/s1600/you_have_mail_installed_inside.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="277" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9lg7lVZHbRsr0a4u4R7BH_jN55IRNtal1TWUfDs5RuQFMFWAaR51kTTQEMJd2f1l9w1RPEWZYz4krsvkqUUsW3Fjj3y4bc0GKRS-7kWUUKUfEXtIu6LCtBXZDB4vmwCHEfXkC6EITfnM/s320/you_have_mail_installed_inside.jpg" width="320" /></a></div>
<br />
<h4>
Software</h4>
For programming I wanted to use <a href="http://www.nodemcu.com/index_en.html">NodeMCU</a> and lua. I wanted to see if a interpreted language would be good enough, and it also has mqtt support.<br />
<br />
Script itself is pretty simple:<br />
<br />
<ol>
<li>wakeup</li>
<li>check if we see light, if so then there is too much light -> error</li>
<li>turn on led</li>
<li>check if we see light, light -> no mail, no light -> mail</li>
<li>send message</li>
<li>sleep</li>
</ol>
<div>
Programming with NodeMCU is pretty straightforward. But because it's event driven there is a bit of extra work with callbacks for this kind of batch job.</div>
<br />
Code can be found here <a href="https://github.com/mika-koivusaari/you_have_mail">https://github.com/mika-koivusaari/you_have_mail</a>.<br />
<h3>
Future improvements</h3>
<div>
After deep sleep check mail status first, and only if it has changed start modem and send message. Not sure how much this would improve battery life, but if it seems too short then I'll try.</div>
<div>
<br /></div>
<div>
Report battery status. Esp8266 only has adc range from 0 to 1 volts, so I would need to scale the voltage from three aaa batteries to that. Need to look into that sometime, it would probably be useful for other projects too.</div>
<div>
<br />
Look for mqtt broker with mDNS, NodeMCU doesn't current have a mDNS client, so this will have to wait for that.</div>
<div>
<br /></div>
<div>
Next I'll have to make some kind user interface so I can actually see when the mail arrives.</div>
<div>
<br /></div>
Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-56251101378945626702016-07-06T12:53:00.000+03:002016-07-06T12:53:49.960+03:00Comparing solar radiation shieldsI have three temperature sensors with <a href="http://timpramist.blogspot.fi/2016/06/calibrating-ds18b20-sensors-to-show-same.html">calibration data</a> that I want to test with different solar radiation shields.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSNVIcgqqVS3PcmTBY0uMCsWaJCFv-4j3C1mZtq7GnHOygqSMeokpd0DJrzCJ4_4zdkxpVh48_V_QgeGbx9S1sBP0xfX0zBD-DAK-5SLMsQ9z4FIfdbSzRvDi_06yJnChJn8FnUxs8NBQ/s1600/solar_radiation_shields.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSNVIcgqqVS3PcmTBY0uMCsWaJCFv-4j3C1mZtq7GnHOygqSMeokpd0DJrzCJ4_4zdkxpVh48_V_QgeGbx9S1sBP0xfX0zBD-DAK-5SLMsQ9z4FIfdbSzRvDi_06yJnChJn8FnUxs8NBQ/s640/solar_radiation_shields.jpg" width="640" /></a></div>
<br />
From the left, normal shield made from plastic plates, tube made from twinwall sheet used in advertisement plates, same kind of tube but with fan.<br />
<br />
Sensors (DS18B20) are read with <a href="http://owfs.org/">OWFS</a> and a small python script that <strike>starts the conversion for all sensors, reads them and then sends them to a Google Sheet using <a href="https://github.com/burnash/gspread">gspread</a>.</strike> For some reason simultaneous conversion doesn't work for me, I get cached values. So I changed the script to just read sensors one after the other. Reading is done every minute. Also writing to Google Sheets is really slow, especially when done cell by cell. So I moved writing to Sheets to a different script that is run once a day.<br />
<br />
Currently data is flowing in nicely, but I forgot to check which sensor is in which shield, so I have to check that the next time I travel to where those sensors are.<br />
<br />
Writing to Google sheets is really easy with <a href="https://github.com/burnash/gspread">gspread</a>, I can definitely recommend it if you need to work with Google sheets.<br />
<br />
Raw data can be found in this <a href="https://docs.google.com/spreadsheets/d/1V9OOICml3TB_kz-c6pKPEQZLdh8nlp5JI1Lb55njau8/edit?usp=sharing">Google sheet</a>.<br />
<br />
Python script in <a href="https://github.com/mika-koivusaari/read_ds18b20_gspread">https://github.com/mika-koivusaari/read_ds18b20_gspread</a><br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-55929938497764657772016-06-16T20:55:00.000+03:002016-06-16T20:55:28.216+03:00Calibrating DS18B20 sensors to show the sameI have a weather station in our summer house. It currently has a radiation shield made from plastic plates for the thermometer. It's "common knowledge" that if you have more air flow through you sensors it reflects more accurately ambient temperature. So forced airflow with a fan would more likely be better.<br />
<br />
I want to test how much better. For this I need thermometers that show exactly the same value in the same temperature. So I'm going to put three sensors in salt water that's heated to about 40 degrees Celsius and then let it cool down to about -20°. Reading sensor values every minute should give a reasonable calibration table.<br />
<br />
Motor in the top is for circulating water so I get more accurate results. It's a bit ugly setup but I only plan on using this for one time so I didn't bother with anything fancy.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj03kFse__e2Vvlad47fxGpt7vlHSOOgRB5aQJvE_F_5qnOhURt0ub0oPIWlOUew0dBcS8c-0VPqiLHR3K97uAgqvqvbFdalgs2AN4vsmHPNvJBq8oW9gF8ilOEt_G3z5SNzFrProK94E/s1600/ds18b20_calib.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj03kFse__e2Vvlad47fxGpt7vlHSOOgRB5aQJvE_F_5qnOhURt0ub0oPIWlOUew0dBcS8c-0VPqiLHR3K97uAgqvqvbFdalgs2AN4vsmHPNvJBq8oW9gF8ilOEt_G3z5SNzFrProK94E/s320/ds18b20_calib.jpg" width="318" /></a></div>
<br />
<br />
Or at least that was the plan. 40° -> 20° went well but after I put the whole thing in the freezer all the DS18B20 sensors stopped working. I'm guessing some moisture related problem. I took the setup out of the freezer and let it heat from about -3° that it had cooled to room temperature. I'm probably not going to leave the test running for the winter so that range should be enough.<br />
<br />
I used screen to read the values from serial "screen -L /dev/ttyUSB1". As cat seems to stop when arduino takes it's time to boot.<br />
<br />
Data is in a Google spreadsheet <a href="https://docs.google.com/spreadsheets/d/1Ek_DFRSZo7noycc-NZM-l9j-DikLOgE_UMnQRu8OEu4/edit?usp=sharing">DS18B20 calibration data.</a><br />
<br />
There are three sensors A, B and C. Here are their maximum differences, and average differences.
<br />
<table border="1">
<tbody>
<tr>
<th></th>
<th>A-B</th>
<th>A-C</th>
<th>B-C</th>
</tr>
<tr>
<th>Max difference</th>
<td>0.4375</td>
<td>0.3125</td>
<td>0.2500</td>
</tr>
<tr>
<th>Avg difference</th>
<td>0.0537</td>
<td>0.0353</td>
<td>0.0433</td>
</tr>
</tbody></table>
<br />
I'm thinking that the differences are not that big and I shouldn't worry about them. And some of it is most likely because I put a different amount of hotglue to the sensors to shield them.<br />
<br />
Code used can be found in github <a href="https://github.com/mika-koivusaari/read_all_ds18b20">https://github.com/mika-koivusaari/read_all_ds18b20</a><br />
<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-5238148913339007202016-06-09T13:32:00.004+03:002016-06-09T13:32:54.490+03:00Arduino counterI needed a way to read pulses from our house and geothermal heat pumps electricity meters. Of course there are many pulse counters all ready, but I had make my own:) Just a simple sketch that counts pulses from pins 2 and 3 reports them on the usb serial when asked.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_zZOdkz9fC_RtMAcjugwf4xrlVC0dpSaIA3fif4WMtSCSlui7ISqBUgrSC4dbHP-gJWB4DAbhJlCFEeTpAbfTP_tKk6HeiT5VEoIzuPAxwWI8tYIFa6l-5-GjqCMXSYa9zKnuJQcT3VY/s1600/WP_20160530_10_40_02_Pro.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_zZOdkz9fC_RtMAcjugwf4xrlVC0dpSaIA3fif4WMtSCSlui7ISqBUgrSC4dbHP-gJWB4DAbhJlCFEeTpAbfTP_tKk6HeiT5VEoIzuPAxwWI8tYIFa6l-5-GjqCMXSYa9zKnuJQcT3VY/s320/WP_20160530_10_40_02_Pro.jpg" width="320" /></a></div>
<br />
Main meter is read optically with a TSL257 and the geothermal pump meter is directly connect to the meter.<br />
<br />
Code in github <a href="https://github.com/mika-koivusaari/read_kwh_pulse">https://github.com/mika-koivusaari/read_kwh_pulse</a><br />
<br />
I use a python daemon to relay the data to MySql, code again in github <a href="https://github.com/mika-koivusaari/read_pulse_mysql">https://github.com/mika-koivusaari/read_pulse_mysql</a><br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-61783670512938669542016-05-30T09:21:00.000+03:002016-05-30T09:21:46.815+03:00Bathroom lightingWe are building a upstairs bathroom. In downstairs we already have the light controlled by a PIR sensors. Which works great, except at night. When you have to go to do your business half sleep and suddenly the lights go at full blast, good luck at getting to sleep after that. I need to have a way to make the lights only light very dim at night.<br />
<br />
So basically the functional specification is as follows:<br />
1. Lights on when someone enters<br />
2. If it's night lights are dim.<br />
3. If it's day lights are fully on.<br />
4. User can manually force full lights.<br />
<br />
Probably the most difficult was figuring out when it's night. A simple clock would only give moderate results because we don't usually go to sleep at a fixed time. I decided to solve the problem with a light sensor in the lobby where you enter the bathroom. If it's day then sun is shining in the lobby, if it's evening and dark outside but you have the lobby lights on then you are not sleeping and want full lights.<br />
<br />
There are three led strips for lighting, and most likely one of them is behind the mirror, they should all be separately controllable to give optimum lighting.<br />
<br />
Pir sensor is just a standard mains voltage pir sensor that switches on the power source that powers the led strips and arduino.<br />
<br />
Full light switch is also a normal mains switch that switch on power source source and gives a signal to arduino that full light is requested.<br />
<br />
For the light sensor I chose <a href="https://ams.com/kor/content/download/250427/976469/file/TSL257S_Datasheet_EN_v1.pdf">TSL257</a>, because I had one lying around and it has linear light to voltage ratio. Power source is just some generic power source from aliexpress. Because the led strips are 24 volts I had to get that down to acceptable level for arduino, for that I used a generic stepdown converter, again from aliexpress. If I used 12 volt led strips I could just use that straight to power arduino. Full light switch gives mains voltage so that needs to transformed to a suitable voltage for arduino to read, an old cellphone charger is fine, just to make sure it gives a voltage below 5V I will put a zener diode in there, and also a bleeder resistor so it doesn't stay on for too long after the power has been cut off.<br />
<br />
For some reason I have problem with the TSL257, when it's on a long lead it doesn't give correct results for some reason. Which is odd because I have one looking at pulses from our electricity meter and it works just fine with a long wire.<br />
<br />
I also put a possibility to set the full brightness, which was nice because two led strips about 2,7 meters long where way too bright.<br />
<br />
I have made the controller to veroboard and it seems to function, it hasn't been installed permanently yet because the mains wiring isn't done yet. I'm not an electronics engineer so this might look somewhat ugly:) In the few days it has been in use I already found a bug, I didn't put any hysteresis in the dark/light sensing part of the code, so in the correct lighting it flickers somewhat.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh20K7ivU0BJX5wTWGnV-GFxwaUMhze_9CJf8YeBa7jeK8k8TLNKNAUbhgjLy7txw2xz9tZHHfG5w90UEjIaLIrOpxYo48fChrJDYoN0g7SncInI1phQcT0XmUXe3AplhB5iYO6_rJBrAc/s1600/light_controller_vero.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh20K7ivU0BJX5wTWGnV-GFxwaUMhze_9CJf8YeBa7jeK8k8TLNKNAUbhgjLy7txw2xz9tZHHfG5w90UEjIaLIrOpxYo48fChrJDYoN0g7SncInI1phQcT0XmUXe3AplhB5iYO6_rJBrAc/s320/light_controller_vero.jpg" width="320" /></a></div>
<br />
Current code <a href="https://github.com/mika-koivusaari/bathroom_light_controller">https://github.com/mika-koivusaari/bathroom_light_controller</a><br />
<br />
I'm in the process of making a schema with Fritzing but I have to first find or make TSL257 for Fritzing.<br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-53439034210183975312016-05-27T22:01:00.000+03:002016-05-27T22:01:15.103+03:00Making a python daemonI have arduino (<a href="https://github.com/mika-koivusaari/read_kwh_pulse">https://github.com/mika-koivusaari/read_kwh_pulse</a>) that counts pulses, and you can then query those counts through usb serial. Currently it measures electricity consumption of our house and geothermal heat pump. I needed a way to store those values in a database.<br />
<br />
I quickly cobbled a script that just read values every minute and inserted them to MySql. It worked pretty fine, except you had to start it manually if something went wrong and when the server was rebooted. So I started to rewrite it to a proper unix daemon, and it's hard:)<br />
<br />
For the serial part I used pyserial. <a href="http://www.varesano.net/blog/fabio/serial%20rs232%20connections%20python">http://www.varesano.net/blog/fabio/serial%20rs232%20connections%20python</a> has a good example.<br />
<br />
Python has a couple of implementations for daemonizing a process, first I tried with <a href="https://pypi.python.org/pypi/python-daemon/">https://pypi.python.org/pypi/python-daemon/</a> but it didn't seem to have good documentation, so I switched to <a href="http://pep3143daemon.readthedocs.io/en/latest/">http://pep3143daemon.readthedocs.io/en/latest/</a>.<br />
<br />
Problems I encountered.<br />
<br />
Security, when you start you can have root privileges, but when you are running you really shouldn't be root. So when you reload your configuration when the user ask and try to open files it's very well possible you can't.<br />
<br />
Signals, you should close all your resources nicely. So you should catch signals like SIGTERM. But I just couldn't get that to work. But it turns out all I had to do was read the documentation. <a href="https://docs.python.org/2/library/signal.html">https://docs.python.org/2/library/signal.html</a> Signal handlers need to take two parameters, signal number and current stack frame.<br />
<br />
Debugging, still haven't figured this one out. Daemon processes need to close all filehandles before becoming a daemon, and I'm guessing that (atleast PyCharm) opens some socket to the process it's debugging and when the daemonize process closes that you can't debug anymore. And it's really hard to find errors when you also don't have stdout or stderr and you haven't yet opened your log file, or there is something wrong with your logging.<br />
<br />
Current code for my daemon is in github <a href="https://github.com/mika-koivusaari/read_pulse_mysql">https://github.com/mika-koivusaari/read_pulse_mysql</a><br />
<br />Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0tag:blogger.com,1999:blog-7434552920886504288.post-88021604477787404992016-05-26T23:19:00.000+03:002016-05-26T23:19:48.839+03:00Outside temperature and electricity usageOur living room/kitchen is on the south side of our house, wireless outside thermometers can't reach it from the north side. But I have a server recording outside temperatures, and maybe a whole weather station in the future. So I only had to display the temperature I already had. We also had an old IPhone and a radio with IPhone dock. So I only had to write a small script that displays the current temperature in a web page and automatically updates. Then use the IPhone to display the page.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTksz9WvOrdZxU-Xu2S6ZO-N8-in28NFxnnJ-0mFTWmSwQz_4NmdVFeWr4tgY2stE-niBYYoYh8ehDP6K39W_57wv6ydssttKkRjJtND1bBpr_Mn5xxyQi5YQ_6lReCmNvxwTrR9V66Q4/s1600/WP_20160526_20_58_27_Pro.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTksz9WvOrdZxU-Xu2S6ZO-N8-in28NFxnnJ-0mFTWmSwQz_4NmdVFeWr4tgY2stE-niBYYoYh8ehDP6K39W_57wv6ydssttKkRjJtND1bBpr_Mn5xxyQi5YQ_6lReCmNvxwTrR9V66Q4/s320/WP_20160526_20_58_27_Pro.jpg" width="180" /></a></div>
<br />
It also displays the electricity consumption in the last minute.<br />
<br />
Maybe in the future I'll build a better app with more information, todays forecast or something. Data could be sent with mqtt maybe.Mika Koivusaarihttp://www.blogger.com/profile/13472094164482665622noreply@blogger.com0