1. Introduction

Non-contact infrared temperature measurement is more and more widely used in medical treatment, environmental monitoring, personal health and other fields. This article will introduce how to quickly complete temperature detection through the WiFi module of Alios-Things Inside. The process covers from sensor data collection to access to alicloud IoT intelligent living platform, as well as the rapid construction of App to complete monitoring. It is hoped that the full set of solutions from the device end to the cloud application provided by Alibaba Cloud IoT can quickly help intelligent equipment manufacturers to build automatic human body temperature measurement equipment and solutions that can replace human labor, reduce the risk of human contact in the prevention and control, and improve the efficiency of investigation.

2. Software and hardware environments

2.1 Software Platform

Cloud — Alibaba Cloud IoT Intelligent living Platform (Feiyan Platform) Life Internet of Things platform provides device access ability, MOBILE SDK and development-free public App and interface, developers can quickly realize intelligent devices based on this platform. Mobile terminal — Cloud Intelligence (public App) Cloud intelligence is a public App provided by the living Internet of Things platform, which requires no additional development and can be directly used for network distribution and control of devices after downloading. Support the search for “cloud intelligence” download in the world’s major app stores; As a lightweight iot OS, AliOS Things supports multiple chips that can easily integrate temperature sensors and connect to the living iot platform through the SDK on the device side. The latest 3.0.0 release is used here.

2.2 Hardware Platform

Hardware platform

The hardware platform adopts ESP8266 nodeMCU, supporting Wifi connection, with I2C, UART and other interfaces, and with keys (FLASH keys), which can be used to trigger the temperature detection report.



Sensor –MLX90614ESF-DCI-000-TU (I2C interface)

The sensor is an infrared non-contact thermometer that supports THE I2C communication protocol. It mainly uses SDA and SCL lines and can be easily connected to the ESP8266 development board.



The instructions are as follows:



Hardware connection

The corresponding relationship between the wiring pins of the development board and the sensor is as follows:

Development board The sensor
D1 (GPIO_05) SCL
D2 (GPIO_04) SDA
3.3 V Vcc
GND GND

Hardware connection diagram, right click to open the larger picture

3. Cloud configuration

Before creating products and devices on the intelligent living platform, please ensure the following two points:

  • Have registered aliyun account and completed real-name authentication. For registration operations, see Alicloud Account Registration Process.
  • The life Internet of Things platform service has been opened.

3.1 Product Creation

You have created projects and products on the console, and completed product function definitions. For details, see Overview. When defining a function, note the following:

  1. Set product type to Thermometer. The standard function already includes Body temperature. You only need to set the value in the data definition to 0 to 99.

  2. As shown in the preceding figure, the identifier used by the device to report the temperature must be consistent with that configured on the cloud (for example, the identifier corresponding to human body temperature in the preceding figure).

3.2 Adding a Test device

Adding a Test Device, record the activation credentials of the device (ProductKey, ProductSecret, DeviceName, and DeviceSecret, as shown in the red box below). You need to configure the activation credentials on the device.

3.3 App Configuration and use

The parameter configuration and process of the public App are as follows:

  1. Enable the control switch of the public App. For details, see Configuring the App Delivery Terminal.
  2. Set App parameters. Product panel, multi-language management, and network boot are mandatory parameters. For details, see Setting App Parameters.
  3. Download the public App (cloud intelligence), refer to the public App introduction;
  4. Scan the QR code of the distribution network and debug the device after binding. For the specific QR code, see Obtaining the QR code of the distribution network.

4. Code migration

To obtainReference code(as shown in the figure) and follow these steps to integrate.

4.1 ESP8266 Board Adaptation

For the ESP8266 development board selected above, in order to ensure the normal operation of key interruption, I2C and other functions, the following modifications are required:

  1. GPIO pins corresponding to FLASH buttons are modified.
  2. I2C bus corresponding pin modification;
  3. 8266 does not support C99 compiler adaptation;

For details, see the attached patch file (001-AOS-3-0-0-ESP8266. patch, generated based on AliOS Things 3.0.0). Copy it to the AliOS Things 3.0.0 root directory and run the following command to infiltrate the patch:

patch -p1 < ./001-aos-3-0-0-esp8266.patchCopy the code


4.2 Driver Migration

MLX90614 is an infrared thermometer used for non-contact temperature measurement, and its usage is mainly introduced here. MLX90614 EEPROM is mainly used for parameter configuration. For details, see the official manual:



MLX90614’s RAM is read-only and users can read data such as temperature. For example, Tobj1 on RAM can obtain the temperature data of the detected object.



The I2C bus accesses the sensor through the device address 0X5A (MLX90614 factory setting). When accessing the RAM and EEPROM, the command mappings are as follows:

For example, access to the address 0X4 on EEPROM (Emissivity correction coefficient) can be obtained in the following ways:

  1. Access is EEPROM, its opcode height is 3 bits 0B001
  2. The last five bits are the address of the access, which is 0X4, or 0b00100 in binary
  3. The operation command is 0B00100100, that is, 0X24

In the same way, the opcode for reading the temperature register (Tobj1) data of the object under test through RAM is 0X7. The driver code for reading the temperature of the object under test (located in DRV_TEMP_MELexIS_MLx90614.c) is as follows:

static int drv_temp_melexis_mlx90614_read(void *buf, size_t len)
{
    int                 ret = 0;
    size_t              size;
    uint8_t             data[2];
    int32_t             temp;
    uint32_t            value;
    temperature_data_t *pdata = (temperature_data_t *)buf;
    if (buf == NULL) {
        return- 1; } size = sizeof(temperature_data_t);if (len < size) {
        return- 1; } /* The Tobj register mlx90614_ctx.config. dev_addr is the device address 0X5A MLX90614_TOBJ1 is the opcode 0X07 */ ret = hal_i2c_mem_read(&MLX90614_ctx, MLX90614_ctx.config.dev_addr, MLX90614_TOBJ1, I2C_REG_LEN, data, 2, I2C_OP_RETRIES); value = data[0] | (data[1]<<8);if (unlikely(ret)) {
        return- 1; } /* Temp = ((int32_t)value * 2) -27315; pdata->t = temp; pdata->timestamp = aos_now_ms();return (int)size;
}Copy the code


Here is how to integrate the driver by copying the driver file drv_temp_MELexIS_mlx90614.c to driversSensordrv and adding the build configuration in the first line of Driverssensordrv.mk.

    ifeq ($(AOS_SENSOR_TEMP_MELEXIS_MLX90614),y)
    $(NAME)_SOURCES += drv/drv_temp_melexis_mlx90614.c
    endifCopy the code


4.3 Use case migration

Copy the use case code (folder) to the AppExample directory and add the use case build configuration in appExampleconfig. in.

source "app/example/thermometer/Config.in"
if AOS_APP_THERMOMETER
    config AOS_BUILD_APP
        default "thermometer"
endifCopy the code


The use-case initialization process is as follows. For details, refer to the entry function application_start:



In McUesp8266bspkey. c, after a key is pressed, the interrupt callback function will trigger different events (aOS_POST_event) according to the duration of the key holding (short press, long press for 2 seconds, long press for 6 seconds). The key callback registered in application_start responds to the above events with the following code:

Void linkkit_key_process(input_event_t * eventInfo, void *priv_data) {if (eventinfo->type! = EV_KEY) {return;
    }

    if (eventinfo->code == CODE_BOOT) {
        if(eventInfo ->value == VALUE_KEY_CLICK) {/* Press (>40ms) to trigger a temperature check and report it to the cloud */ app_sensor_test(); }else if(eventInfo ->value == VALUE_KEY_LTCLICK) {/* Hold down (>2s) to trigger the system to enter network mode */ do_AWss_active (); }else if(eventInfo ->value == VALUE_KEY_LLTCLICK) {/* Hold down (>6s) to clear network information and reset the system */ awss_reset(); }}}Copy the code


Please refer to relevant codes for temperature data detection and reporting process. If the temperature is below the normal range of human body temperature (34-42 ℃), 0 will be reported; if the temperature is higher than the normal range of human body temperature, 99 will be reported:

/* Read the temperature data and report to cloud */ voidapp_sensor_test() { int ret; char param[128]; temperature_data_t temp; Double data = 0.0; */ ret = sensor_hal_read(TAG_DEV_TEMP, 0, &temp, sizeof(temp));if(ret <= 0){
        printf("\nSensor data read fail \n");
        return; } data = (double)temp.t; Data = data / 100.0; /* Human body temperature data calibration */ data = data - (data *data *data *data *data *data *data *data) * 0.000125 + (data *data *data *data *data *data *data) * 0.0283429488 - (data *data *data *data) * 2.67004808 + (data *data *data) * 133.762569 - (data *data) * 3758.41829 + (data) * 56155.4892-348548.755;if(data < 34.0) {data = 0.0;printf("\nNot the normal range of human body temperature (34 ~ 42℃) \n");
    }
    else if(data > 42.0) {data = 99.0;printf("\nNot the normal range of human body temperature (34 ~ 42℃) \n"); } /* Network connection detection */if(! app_conect_check()) {printf("\nNetwork is not connected\n");
        return; } memset(param, 0, 128); /* Build the payload */ sprintf(param, PROP_POST_FORMAT_TEMP, data); /* Report temperature data to cloud */if(app_init_check() ! = 0) { ret = IOT_Linkkit_Report(app_device_get(), ITM_MSG_POST_PROPERTY, (unsigned char *)param, strlen(param) + 1);if (ret == -1) {
            LOG("%s %d fail\n", __func__,__LINE__); }}}Copy the code


4.4 Modifying a quad

Update the device activation credentials (quads) documented in Section 3.2 to the device side (in app_entry.h under the AppexamplePole directory) :

#define PRODUCT_KEY "xxxxxxxxxxx"
#define PRODUCT_SECRET "xxxxxxxxxxxxxxxx"
#define DEVICE_NAME "xxxxxxxxxxxxxx"
#define DEVICE_SECRET "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Copy the code


4.5 Identifier Confirmation

For details, see Section 3.1. Ensure that the function identifiers (in app_Entry. h in the AppexampleSucceeds directory) corresponding to the temperature reported by the device are consistent with those configured on the cloud platform.

#define PROP_POST_FORMAT_TEMP "{\"BodyTemperature\":%.1f}"Copy the code


5. Compile and run

5.1 build

  1. Run the following command in the OS directory to complete the compilation
  2. make thermometer@esp8266 -c config

aos make

  1. The generated firmware [email protected] is in the outthermometer@esp8266binary directory
  2. Use the Flash download tool (FLASH_DOWNLOAD_TOOLS) of ESP8266

5.2 run

Development board reference is as follows:



After resetting the board, hold down the “FLASH” key (>2s) to start the network configuration process. On the APP end, refer to the”Public App usage process”Complete.

After the network is configured successfully, press the “FLASH” key (>40ms) to trigger a temperature collection, upload the temperature to the cloud, and push the temperature to the smart cloud APP on the mobile phone side.



Read more: https://yqh.aliyun.com/detail/6364?utm_content=g_1000105251

On the cloud to see yunqi: more cloud information, on the cloud case, best practices, product introduction, visit: https://yqh.aliyun.com/