未加星标

A Thermostat Weekend

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

As it happens, a few days ago, reader Antonio pointed me to a little ESP8266 Thermostat well, some code for it anyway, using one of those little 120*180 displays.


A Thermostat Weekend
I’m not that partial to Arduino development but I grabbed the code and stuck it on my hardware. Some great ideas there but the implementation using a rotary encoder left something to be desired and the code doesn’t support MQTT and minus temperatures messed the display up. Oh and it seems to be partly in Italian and partly in English. Oh and a good but not especially long-lasting sensor is sitting right next to warm electronics and a warm display.

Don’t get me wrong, a STERLING effort and no doubt it will go on to be very good but it wasn’t quite what I was looking for. It certainly fired me up.

As you all by now know I’m an MQTT/Node-Red/Mobile phone kind of guy and so armed with my new knowledge of Node-Red Desktop I sat down with coffee this morning and started to put together some new thermostat code (as if I needed more). One of the things I really liked about the ESP code was the timing page you see above. I have 5 time zones per day which can be any temperature different at the weekend but not without it’s issues what if the weekend is not your “special” time for example and it needs lots of controls.

This on the other hand was simple. I got to thinking but if it was on a touch screen you would not have all that selecting nonsense and what about replicating settings for every day and….

And so it was that I sat down with a gallon of coffee and did what I always do plough in with the code long before I’ve put a plan together. Sometimes it works, sometimes it doesn’t. Hey, I’m a one-man team!

Well, this time it did and I’m chuffed, but before getting into this a quick lesson on using TEMPLATES in Node-Red Desktop.

Templates are easy pretty much you can make a web page in a template you can even have includes and JQuery comes with the deal. The problem I’ve always had in the past is getting stuff in and out of the template the examples given really don’t help and I spent HOURS trying to get to grips with this.


A Thermostat Weekend
When we were messing with buttons I got a lot of help from folk, most of it I understood, getting variables into the Template I most definitely did not but it worked and now the light is coming on. Remember the good old days of ASP programming and other server-side interpreted coding you had this code on the server which was NOT in the same space as the code in the web page. Well, this is similar. The likes of msg.payload sits in Node-red along with global variables, context variables etc. They do NOT reside in run-time javascript on the web page and that had me going in circles for ages. Well, there is a way around it, digging through the code we ended up with for the buttons. (function(scope){
scope.$watch('msg', function(data) {
// do stuff in here with msg… which includes any part of msg, even arrays etc.
});
})(scope);

So here we are on the web page in a script tag and we drop this in. I know what the HELL is scope. I can’t tell you in detail but I can tell you it works! As soon as you inject the normal Node-Red msg (entire) object into the template where that comment is above, you can use the lot just change “msg” to “data”. So msg.payload becomes data.payload.

Along with the ability to fire out information back to Node-Red with this and similar..

ng-click="send({payload: 'hello world'})"

when buttons are pressed etc.. you now have full input and output to your web-page. With that realisation I started on my new little thermostat. The most COMPLICATED page is that of settings and the project above that I really liked - got me started as gives you 24 settings every day of the week. FANTASTIC but I had to make it easy. Now, it is REALLY easy. You can set up programs for the entire week in a minute.

Over on the right you see my interpretation of this yes, it works I just don’t have a relay fastened up yet to DO something.

Ok the ICONS could be better and the colours need to be more subtle don’t be awkward I only started this after a fear-filled, anaesthetic-devoid double-crown fitting at the dentists via a 90+ mile round trip. yes, I AM brave though it nearly reduced me to tears so bear that in mind before criticising my colour taste.

So you can touch/click on any of the timings or temperature, or day and using the up and down buttons (they’ll end up as left and right arrows) you can change the temperature from one of the presets for that time or the time slot you are playing with or the day. The black line under the relevant item will turn purple (for now).


A Thermostat Weekend

If you want to replicate the setting on subsequent hours, press/touch the copy button as often as you need (auto-increment). If you want to replicate the LOT, click on the DAY and then on the copy button and you’ll start whizzing through the days (auto-increment), coping the entire 24-hour schedule across you can then tweak bits later. When you are happy you’ve not messed anything up press the save button.

Now this lot is simply stored in an array 24*7 bytes plus 4 bytes for the temperatures so as an array, stored on SD it takes up almost no room by using a 2-level array you could EASILY expand this into different ZONEs so as well as a DAY field you’d have a ZONE field and a copy operation would copy the whole lot to the next zone etc etc. Seriously this is a DODDLE to set up.

Oh, I forgot cancel… right imagine a cancel button…which simply restores the array from SD.

So now we have a non-volatile global array with all the info in (I jammed the temperature settings on to the end of the array) a separate page will show the temperature with a nice pretty dial, let you change manually up and down that for a given time what, 4 hours before reverting to auto? and of course you’d want to show the humidity and pressure very important they are all super accurate so I’m thinking a single BME280 would do the lot for you!!!

And that’s it the main page will no doubt feature the local weather forecast again from a previous article. One could even add a complete week’s predictions.

But that, I’m afraid is it for now midnight and time to give up after a very productive Saturday. More on this in the coming days including of course the FLOW for this so you can just drop it in into Node-Red. Aren’t you glad you adopted the latter!

Now, is auto-learning possible/worthwhile? I’m in too minds easy enough to watch what you are doing and make subtle adjustments but more than once I’ve read about people turning this feature off. We don’t all have repeatable, robotic routines from week to week.

That’s it for now more later. Good night all.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: ArduinoJavaTI
分页:12
转载请注明
本文标题:A Thermostat Weekend
本站链接:http://www.codesec.net/view/520803.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(21)