📜 ⬆️ ⬇️

Internet thermometer or telemetry of a country house

I built a "country" house, because I do not live in it, I ran into the problem of determining the temperature. At the construction site lives mother-in-law. Water in the heating system is recruited. It was determined experimentally that at +8 in the house, the pipes on the walls behind the plasterboard begin to freeze, and at +18 the mother-in-law is sick. So there was an idea to monitor the temperature remotely.

After searching the Internet, 2 devices were purchased: domestic production VM1707 and Chinese termoHID . The software was attached to both. Chinese art was nalapisto, but the functionality slightly surpassed ours, but up to 10 DS18B20 sensors can be connected to our device. This argument was decisive.

Now in the system 4 sensors, street, 1st floor, 2nd floor and attic. Accumulated year of statistics. The front looks like this:


ATP Dennsy thermometer in the openweathermap.org project, the station is here .
ATP SSar thermometer in the project narodmon.ru, the station here .
The native site tarasii.dyndns.org due to the limitations of windows xp falls upon 10 connections.
')
BM1707 software can record measurement results in text files. So, for a long time without thinking about ASP, a file-to-table converter was thrown. It was not easy to read such tables, and most importantly it is difficult to notice the moment when the temperature is still not normal. It was here that colleagues (ATP KOJISI) came to the rescue, and pushed on the right road. Javascript Highstock came into view. How it is used in Highstock articles: monitoring the Runet Award and Dynamic graphics based on highstock .

After some vigilance, the tables on the ASP were combined with JS. In fact, the graphics turned out to be the same as now, but they were built by files. After two months of work, the files had to be abandoned. File processing lasted an incredibly long time. The decision was made with lightning speed - we read graphs from MySQL. The BM1707 software allows you to periodically poll sensors and then execute bat files. A VBScript was written which stores the measurement results in MySQL. The script has a text date to date conversion in seconds since 1970, as well as a check for the existence of a record with such a time.
Const ForReading = 1 Const TristateUseDefault = -2 Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") Dim FilePath FilePath = "C:\BM1707\bm1707.temp" set cn = CreateObject("ADODB.Connection") cn.connectionstring = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;DataBase=test; " &_ "USER=usr;PASSWORD=psw;" cn.open If FSO.FileExists(FilePath) Then Dim file Set file = FSO.GetFile(FilePath) Dim TextFileStream Set TextFileStream = file.OpenAsTextStream(ForReading,TristateUseDefault) Do While Not TextFileStream.AtEndOfStream Dim line line = TextFileStream.ReadLine curday = Mid(Line,2,2) curmnth = Mid(Line,5,2) curyear = Mid(Line,8,4) curData = Mid(Line,2,10) curhour = Mid(Line,13,2) curmin = Mid(Line,16,2) cursec = Mid(Line,19,2) curdt = curyear & curmnth & curday & curhour & curmin & cursec curhour = Cint(curhour) curmin = Cint(curmin) cursec = Cint(cursec) aspdate = CDate(curData) javadt = ((((aspdate - 25569) * 24 + curhour) * 60 + curmin) * 60 + cursec) * 1000 sqlStr = "SELECT Count( * ) FROM temperatures WHERE javadatetime = " & javadt res = cn.execute(sqlStr) if res(0)="0" then line = trim(Mid(Line,24)) cnt = 1 lst = Split(line) for each str in lst nm = "" val = "" vals = Split(str,"=") for each z in vals if nm = "" then nm = z else val = Replace(z,",",".") end if next if (nm <> "") and (val <> "") then cmdStr = "INSERT INTO temperatures" &_ "(measurementdatetime, thermometerid, value, javadatetime, thermometername)" &_ "VALUES ('" & curdt & "','" & cnt & "','" & val & "','" & javadt & "','" & nm & "')" cn.execute cmdStr End If cnt = cnt + 1 next End if Loop TextFileStream.Close Set TextFileStream = Nothing End If cn.close 

Next is a PHP adapter that generates JSON for Highstock.
 $rcn = mysql_connect("localhost","usr","psw"); mysql_select_db("test"); $termid = " and `thermometerid` = 2"; $last = "order by `measurementdatetime`"; $from = ""; $to = ""; $funk = "MIN"; if (isset($_GET['termid'])) $termid=" and `thermometerid` = ".$_GET['termid']; if (isset($_GET['last'])) $last="order by `measurementdatetime` desc, 'termid' limit ".$_GET['last']; if (isset($_GET['from'])) $from=" and `measurementdatetime` >= ".$_GET['from']; if (isset($_GET['to'])) $to=" and `measurementdatetime` <= ".$_GET['to']; if (isset($_GET['funk'])) $funk="".$_GET['funk']; $sqlstr = "SELECT MIN(`javadatetime`) as javadatetime, ROUND(".$funk."(`value`),1) as value FROM `temperatures` WHERE 1 ".$termid." ".$from." ".$to." group by TO_DAYS(`measurementdatetime`) ".$last; $res = mysql_query($sqlstr); $number = mysql_num_rows($res); printf("["); $first = false; if ($number > 0) { while ($row=mysql_fetch_array($res)) { if ($first) printf(","); printf("["); printf($row['javadatetime']); printf(", "); printf($row['value']); printf("]"); $first = true; } } printf("]"); mysql_close(); 

Example of graphics output:
  var cnt = 0, seriesOptions = [], names = ['MAX','AVG', 'MIN']; createAll(); function createAll() { cnt = 0; $.each(names, function(i, name) { $.getJSON('http://tarasii.dyndns.org/minmax.php?termid=2&funk='+name, function(data) { seriesOptions[i] = {name: name, data: data, tooltip: { yDecimals: 1}}; cnt++; if (cnt == names.length) { createChart(); } }); }); } function createChart() { window.chart = new Highcharts.StockChart({ chart : { renderTo : 'container'}, title : { text : 'Day Temperature Statistics'}, xAxis : { maxZoom : 1 * 24 * 3600000 // fourteen days}, series : seriesOptions }); } 

Recently, again, colleagues have pushed me to the jQuery gauge widget (ATP ASM). It turned out analog thermometers and clocks
  function createGauge(inGauge) { inGauge.jqxLinearGauge({ orientation: 'vertical', width: 80, height: 150, ticksMajor: { size: '10%', interval: 10 }, ticksMinor: { size: '5%', interval: 2.5, style: { 'stroke-width': 1, stroke: '#aaaaaa'} }, max: 40, min: -40, pointer: { size: '5%' }, colorScheme: 'scheme05', labels: {position: 'far', interval: 20, formatValue: function (value, position) { if (value === -40) { return '°C'; } return value + '°'; } }, animationDuration: 100 }); }; 

Script that sends results to openweathermap
 On Error Resume Next set cn = CreateObject("ADODB.Connection") cn.connectionstring = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;DataBase=test; " &_ "USER=usr;PASSWORD=pwd;" cn.open sqlStr = "SELECT t.value as vl, transactiondatetime,thermometername FROM temperatures t where thermometername='Outdor' order by transactiondatetime desc limit 1; " res = cn.execute(sqlStr) str = FormatNumber(res(0),1,-1,0,0) str = Replace(Str,",",".") cn.close Set cn = Nothing strURL = "http://openweathermap.org/data/post" strDatatoSend ="user=usr&password=pwd&temp="&str&"&lat=50.5193&long=30.5915&alt=100" Dim objHTTP Set objHTTP = CreateObject("Microsoft.XMLHTTP") 'Create XML HTTP object for the Post method objHTTP.open "POST", strURL, False, "usr", "pwd" 'Opening the HTTP post method objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" objHTTP.send strDatatoSend 'Sending the request Set objHTTP = Nothing 

An example of a gadget for windows7 which shows the temperature from the openweathermap station
The data is read by the jquery script.
 function updateList() { $.getJSON('http://openweathermap.org/data/2.1/weather/station/46933?type=json&callback=?', function(json) { $.each(json, function(i, head) { if(i=="main"){ curTmp = Math.round((head.temp-273)*10)/10; if (curTmp>0){ $('#main').html('<p>+'+curTmp+'°C</p>'); }else{ $('#main').html('<p>-'+curTmp+'°C</p>'); } } }); }); } 


A little about the equipment.

The BM1707 controller is connected to DS18B20 sensors by a twisted pair, the sensors are connected in parallel. Tire length about 10 meters.

At first, the server was an EeePC900H netbook running WIN XP. After some time, the server moved to the miniITX VIA C7-D 1800MHz in the old AT package.


By the cost of components including the "server" you can keep within $ 100

I hope this article complements the Electronic thermometer with a web interface based on UniPing RS-485

Source: https://habr.com/ru/post/155869/


All Articles