How to put thermometer to your WEB page?

Do you want your website to show a thermometer like ours? Are you looking for a way to show the temperature in your premises or sport facility directly on your web? This article is the right one for you. Here, you will learn how to measure the temperature and how to get the values onto your web.

How does it work?

A thermometer or a special program sends the currently measured temperature to the web server as a simple query of the HTTP GET type.

Drawing of the principle of measured temperature inserting on the WEB pages in case of TM and TMU. As for TME the temperature is sent directly to the server without any need for help from the measuring station.

Figure 1. – The principle of displaying temperature on your website

What hardware to use?

The temperature is measured using a TM (thermometer for RS232), TMU (thermometer USB) or TME thermometer (Ethernet).

Web thermometer in PHP

What is necessary for this solution:

  • Hosting (or an intranet server) with PHP scripting.
  • Computer with a connected TM or TMU temperature sensor making regular connections to the Internet, or a TME thermometer connected permanently to the Internet.

The systems of temperature measuring and updating on the WEB is illustrated in the figure above. At the point of measurement, a TM or TMU temperature sensor is connected to a computer running the control program. In regular intervals, the program measures the temperature from the sensor and sends it to a server connected to the Internet (or Intranet).

In case of the TME Ethernet thermometer, the process of sending the measured temperature is even simpler. The interval for sending the measured value as well as the internet address of the script processing the temperature is set directly in TME. This is the only setting that needs to be done in this version.

On the server, the only thing you need to do is to place a simple script on the WEB site (described below), which saves the received temperature and makes sure it is displayed at a desired location of your website.

[ The below described solution of temperature data transfer is the most basic example of available solutions. Naturally, this solution should also include security or should be able to deal with long-term loss of communication with the server. ]

Script

The source code of the script on server:

<?php
// Test if a variable temp exists in http get
if (isset($_GET['temp'])) {

    // Load variables from the temp sensor and protected against XSS attacks
    $TEMP = htmlspecialchars($_GET['temp'], ENT_QUOTES, "UTF-8");

    // If the temperature comes as a parameter, write it in a file and displays the results
    // If the file has the appropriate rights, displays an error message
    if ($file=@fopen("temperature.dat", "w")) {
        $text=fwrite($file,$TEMP);
        fclose($file);
        echo $TEMP;
    } else {
        echo "Error - file temperature.dat does not have permission to write!";
    }

} else {

    // If the temperature does not come as a get parameter, loads and displays the temperature from file
    // If the file has the appropriate rights, displays an error message
    if ($file=@fopen("temperature.dat", "r")) {
        $text=fread($file,10);
        fclose($file);
        echo $text;
    } else {
        echo "Error - file temperature.dat has no permission to read!";
    }
    
}
?>

The script enables both the receipt of the measured temperature and its displaying. The relevant code can simply be stored as a teplota.php file into the root folder of your WEB. If the Internet address of your server is for example www.example.com, the address of your script will be www.example.com/temperature.php. The measured temperature can be stored on the server using the parameter handed over to the script. The temperature of 25.6°C can be entered the following way: www.example.com/temperature.php?temp=25,6. Use this method to test the functionality of the script. Temperature is transferred this way using the operating program which is described below.

If you consequently open the address www.example.com/temperature.php in your Internet browser, the text “25.6” is displayed (the last measured value of temperature).

[ The script for saving the current temperature uses the teploty.dat file, which can be found in the same directory as the script. It is necessary to ensure that the PHP server is fully entitled to write as well as read the file. ]

Now, the script on the server has been finished. Naturally, we can incorporate it into our WEB site or extend it by other functions or security. Regular update of measured temperatures is ensured by an application described below. (The application is not required if temperatures are measured using the TME Ethernet Thermometer, which sends the measured temperature directly to the Internet without requiring any PC.)

Program for temperature measuring

What is required for this program:

  • A computer with Windows 2000, XP operating system or higher.
  • Permanent or regular connection to the Internet. (required for sending temperature values to the server in the Internet.)
  • A connected TM or TMU thermometer.
  • [ If a TME thermometer is used, the application is not required. TME sends the temperature values by itself without requiring any PC. ]

The operating program makes sure that the temperature is measured by the TM or TMU sensor and sent to a server in the Internet. It enables the user to set the intervals of measuring and is able to save measured temperatures into a file, which can be easily imported into the Microsoft Excel program. The program must run on the computer which is connected to the thermometer.

The picture shows all the program windows.

The figure shows all program windows. The main window can be found on the left at the bottom with a minimized main window above it. The right window enables parameter setting.

Main window

The main window shows the measured temperature and the procedure of sending the temperature to the Internet, including any errors occuring in the communication with the sensor or the server. The logs displayed in this window can also be stored in form of a text file of the following format: TM2web - dd.M.yyyy.log. The file is stored in the same directory as the program.

The button to the right of the temperature value can be used to minimise the main window into a stripe (the upper left-hand side of the picture).

The Options button opens the setup window, the Hide button hides the main window on the bottom bar in the area of the clock.

Setup window

Target URL address – the address of the script processing temperature values on the server in the Internet. By clicking the Send button it is possible to send the currently measured value to the set address.

Period of automatic sending to server – the intervals in which temperature values are to be sent to the server in the Internet. The time needs to be set in minutes. If “0” is chosen, the function of automatic sending is deactivated.

Source serial port – from the list choose the COM serial port with the connected TM thermometer or choose a virtual serial port of the TMU thermometer. Click the button to the right of the COM selection field to open/close the selected port for communication with the sensor. If the “Automatic” box is ticked, the selected port is open automatically after the program has been started.

Other settings – saving temperatures into a text file

Always on top – the main window will always be on top of other windows.

Generate temperature LOG – a text file with measured temperatures will be stored every day into the directory containing the program. The temperature files hold names of the following format: Temperature(dd.M.yyyy).log. Each line contains one log including the date and time of measurements. The values are separated by tabulators, which makes the files easy to import into e.g. the Microsoft Excel program.

The setup window can be closed without accepting the changes by pressing the “Close” button or the changes can be saved and the window closed by pressing the ”Save and close” button.

Images


tweb_sw.ziptweb_sw.zip

Program for sending the temperature of the TM and TMU on the web server.

File size: 285 kB

Date: 01-31-2011

Download

Created1/21/2011
We value your privacy
This website stores cookies that help it to work properly. By using our services, you agree to their use.
Allow everythingDetailed settings