Skip to main content

IoT temperature sensor with ESP8266 using LWM2M (Eclipse Wakaama)

The sensor uses an ESP8266 board with the protocol Lightweight M2M to communicate the temperature read by DS18B20 to the gateway. The sources of the project are available on GitHub:


The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability produced by Espressif Systems. The avalability of same SDK allows the chip to be programmed, removing the need for a separate microcontroller. To program the microchip i use the SDK Arduino core for ESP8266 WiFi chip and PlatformIO, that is an open source ecosystem for IoT development.


Lightweight M2M is a protocol from the Open Mobile Alliance for M2M or IoT device management and communication. It uses CoAP, a light and compact protocol with an efficient resource data model, for the application layer communication between LWM2M Servers and LWM2M Clients.
Each service on a constrained device/sensor/actor is modelled as an LWM2M object instance. An object has a unique identifier and may have instances. Some LWM2M object identifiers are standardised via the OMA Object & Resource Registry (


I use libWakaamaEmb by David Gräff,  to enable LwM2M on the ESP8266, with a little change to fix the connection to a server without a bootstrap server. You can find the changes at following repository:
The library libWakaamaEmb is published to the PlatformIO library registry and Arduino library registry and available on Github. I use the PlatformIO and copy the library direcory under my project "lib" folder but i need to select lwip version 2. PlatformIO doesn't allow to select lwip version 2 so i need to change manually the file .platformio/packages/framework-arduinoespressif8266/tools/ replacing lwip with lwip2.
To expose the temperature i implement the object 3300 that rapresents a generic sensor.

 * Implements a generic sensor
 *                 Multiple
 * Object |  ID  | Instances | Mandatoty |
 *  Sensor| 3300 |    Yes    |    No     |
 *  Ressources:
 *              Supported    Multiple
 *  Name | ID | Operations | Instances | Mandatory |  Type   | Range | Units |      Description      |
 *  value|5700|    R       |    No     |    Yes    |  Float  |       |       |  Sensor Value         |
 *  unit |5701|    R       |    No     |    Yes    | String  |       |       |  Sensor Units         |
 *  minv |5601|    R       |    No     |    Yes    |  Float  |       |       |  Min Measured Value   |
 *  maxv |5602|    R       |    No     |    Yes    |  Float  |       |       |  Max Measured Value   |
 *  minr |5603|    R       |    No     |    Yes    |  Float  |       |       |  Min Range Value      |
 *  maxr |5604|    R       |    No     |    Yes    |  Float  |       |       |  Max Range Value      |
 *  appt |5750|    R/W     |    No     |    Yes    | String  |       |       |  Application Type     |
 *  type |5751|    R       |    No     |    Yes    | String  |       |       |  Sensor Type          |
 *  reset|5605|    E       |    No     |    Yes    | Opaque  |       |       |  Reset Min and Max    |

To connect a server witouth the bootstrap server i need to add manually the server address:

#define LWM2M_SERVER_ADDR "coap://"

lwm2m_add_server(123, LWM2M_SERVER_ADDR, 100, false, NULL, NULL, 0);


The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition, the DS18B20 can derive power directly from the data line ("parasite power"), eliminating the need for an external power supply.

I use the DallasTemperature library of arduino to read the temperature by DS18B20.

#include <DallasTemperature.h>

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);


numberOfDevices = DS18B20.getDeviceCount();
Serial.print( "Device count: " );
Serial.println( numberOfDevices );

lastTemp = millis();

// Loop through each device, print out address
for(int i=0;i<numberOfDevices; i++){
  // Search the wire for address
  if( DS18B20.getAddress(devAddr[i], i) ){
    //devAddr[i] = tempDeviceAddress;
    Serial.print("Found device ");
    Serial.print(i, DEC);
    Serial.print(" with address: " + GetAddressToString(devAddr[i]));
    Serial.print("Found ghost device at ");
    Serial.print(i, DEC);
    Serial.print(" but could not detect address. Check power and cabling");

  //Get resolution of DS18b20
  Serial.print("Resolution: ");
  Serial.print(DS18B20.getResolution( devAddr[i] ));

  //Read temperature from DS18b20
  float tempC = DS18B20.getTempC( devAddr[i]);
  Serial.print("Temp C: ");


  1. Really nice article thanks to share with us. I would like to share it with

  2. Can I use leshan demo server to view my client?

  3. Very valuable information, it's not like all the blogs that we find here, congratulations, I was looking for something like this and found it here. Thank you for sharing this blog here. Thermistors for sale online in USA

  4. I read your post and got it quite informative. I couldn't find any knowledge on this matter prior to. I would like to thank you for sharing this article here. watlow f4t

  5. Golden Nugget Casino - Mapyro
    Golden Nugget Casino is a hotel and casino located in 사천 출장마사지 Las Vegas, NV. 울산광역 출장마사지 The casino is owned and operated by Vici Properties. The casino 천안 출장샵 is owned and 강릉 출장샵 operated 인천광역 출장안마 by

  6. A very delightful article that you have shared here. Your blog is a valuable and engaging article for us, and also I will share it with my companions who need this info, lights LED Thankful to you for sharing an article like this.

  7. I always check this type of advisory post and I found your article which is related to my interest. hire fairy lights for wedding, This is a great way to increase knowledge for us. Thanks for sharing an article like this.


Post a Comment

Popular posts from this blog

Smart solar water heating solution to take part in the Open IoT Challenge 4.0!

Smart solar water heating solution uses IoT and AI technologies to improve the efficiency of passive solar water heating system. This solution is designed to take part in the Open IoT Challenge 4.0! Solar water heating Solar water heating (SWH) is the conversion of sunlight into heat for water heating using a solar thermal collector. Solar water heating systems include storage tanks and solar collectors. There are two types of solar water heating systems: active, which have circulating pumps and controls, and passive, which don't. Passive solar water heating systems are typically less expensive than active systems, but they're usually not as efficient. However, passive systems can be more reliable and may last longer. The solar panels heat the water in the storage tank when they are affected by the sun rays. The water reaches the highest temperature when the sun is stronger. If the water in the solar panel is hot the divert valve close the flow towards the boiler s

Connect wan automatically at boot and after a disconnection on OpenWrt

OpenWrt is an open source project for embedded operating system based on Linux, primarily used on embedded devices to route network traffic. I install OpenWrt on my Netgear DGN3500, an ADSL2+ gateway with wireless acccess point integrated. Finally the wifi signal is strong but the internet connection does not go up at boot or after a disconnection. Found solutions I find the following solutions: to schedule the reboot and the reconnections by cron ( ), to write a script to reconnect after a disconnection ( ) or to insert the command "ifup wan" in the file "/etc/init.d/network". Recomended solution To take all the advantages of the previous solutions i write the script "wanup" to connect the wan and i call its at boot and after the disconnection. To call the script "wanup" at boot yo