Home Smart Mesh

Ultra low cost DIY IoT Framework. Wireless sensors and RF repeaters for Raspberry Pi. Open Source, plugs with MQTT and OpenHAB2.

Similar projects worth following
The Internet Of Things should not be the next social gap. To avoid that, we need open standards and cheap Hardware. Home Smart Mesh stands for the focus on the Home use cases (types of sensors, number of nodes, reach,...). This is a free time based hobby project, long time running, no commitment, long breaks, the purpose is to learn new technologies and keep updated with the community tools and standards.
The result is two main HW boards. The CR2032 battery powered wireless node for Temperature, Humidity, Pressure, Ambient Light and Magnetic Switches (window open detection) the power consumption is quite good more than a year of 30 sec update. The second is a fixed node (RF but needs power) that can be both an RF repeater in stand alone or an RF dongle for a Raspberry Pi. The fixed node can also control an RGB LED WS2812B.
The Raspberry Pi Software is developed in C++ and connects with an MQTT client to Mosquitto. OpenHAB2 is configured with MQTT in both directions to Mosquitto.

Introduction to the Project

  • Challenge
    • Internet access creates a social gap, now that things get connected, we see another gap because such devices are expensive and their development environment are expensive and complex. We also have the problem of users not owning their products due to registrations and fees.
    • Although we face many problems on what an IoT device can do, the challenge here is not only to create one more IoT device that can do something but also how to make it as much accessible as possible.
  • Solve the Problem
    • This project solves the cost problem by bringing the world's cheapest development environment for an IoT device. The STM8 components, the STM8 as breakout modules and the ST-Link_v2 programmer are all you need to have debug included for less than what your first coffee can cost.
  • Change the World
    • Even if a one time investment is not significant for some lucky hobbyist, imagine the impact if we want to provide one dev kit per kid in a 500 pupils school, then for 36 schools in each of 25 countries.
    • same for someone thinking big for a startup or simply a hobbyist that still wants to test with 20, 30 or 50 smart nodes, the cost add up quick.
    • IoT devices usually add a function to already existing devices, but it does not make sense if they make them 2x times bigger or 2x times more expensive. The ultra low cost thus opens the doors to much wider low cost products range.
    • This project is completely hobby based without any lucrative purpose, any income generated by any unexpected prize will be entirely invested in dev kits donations. If your organisation would like to donate directly by itself, you can contact me for a suggestions of motivated communities, clubs, associations,...
  • Licenses
    • Discussed in the section below (Hacker's License), basically everything contributed specially to this project is beyond the standard openness as it explicitly allows change of ownership, OWN your things.
    • That excludes of course any 3rd party licenses that have been used, which has been minimized as the peripheral drivers and the Board Support Packages for the STM8S and STM8L have been rewritten from scratch. The web gui has also avoided any restrictive license by directly using d3js.

Links to project Logs

The Logs consist of specific use cases based on this IoT_Framework going into some details of firmware and software :

  • Completely Hackable IoT dashboard : The web technology behind the dashboard that allows you to hack the GUI while the access itself is highly secured. A good example on how you can own your IoT devices, private local network, no third parties, not even for remote access!!!

Where are the Wireless Sensors ?

I think that the wireless sensors are a base for the T (Things) from the IoT. Otherwise Internet do a great job already with wifi connected nodes. But wifi is not low power friendly and with high power you loose the wireless freedom. No the Amazon Dash button is not a good wireless wifi object as it is limited with the number of clicks that leave it out for the major use cases.

I'm trying every day to review the existing development environment on the market for wireless smart sensors that we can directly buy, and the result is either not flexible enough, expensive, complicated to program or all of that at the same time.

The products on the shelves are way too expensive, require each a new custom gateway way more expensive than the expensive sensor.

The best answers came only from hobbyist initiatives where I could...

Read more »

Eagle design sources, cam and bom with Hacker's license, own this design.

x-zip-compressed - 149.28 kB - 04/27/2017 at 18:42


View file

  • 1 × STM8S103F3 breadboard Microprocessors, Microcontrollers, DSPs / Microcontrollers (MCUs)
  • 1 × nRF24L01+ Nordic's 2.4GHz Radio Transceiver
  • 1 × STM8L151F3 Low Power 8bit Microcontrollers in TSSOP20 Package
  • 1 × BME280 Sensor for Temperature, Humidity, Pressure
  • 1 × MAX44009 Ambient Light Sensor
  • 1 × MRMS211H Magnetic Switch Sensor
  • 1 × Fixed Node PCB PCB for the STM8S and nRF
  • 1 × Wireless Node PCB PCB for the STM8L and Sensors
  • 1 × Serial to USB converter Easier connection of the fixed node PCB to the Raspberry Pi
  • 1 × Raspberry Pi 3 Model B Reference model for all of the SW installations and tests

View all 12 components

  • Smart LED Panel - MQTT to x216 WS2812B

    Wassim2 days ago 0 comments


    • This demo is just a picture where the RGB Panel is switched on next to its STM8S_RF_Dongle which is here an RF to WS2812B converter.

    How is this working ?

    • The STM8 firmware to control the WS2812B has already been presented in this Log and the LED series up to 60 here
    • Here we push the number of LEDs up to x216, it could go up to x220 but then it would not be aligned any more. The panel offer up to x256 LEDs but the STM8S memory of 1KB reaches its limit here. For a single color I could simply rework the function to lightup an unlimited number of WS2812B, but we would then loose the option of displaying figures or messages.
    • Every WS2812B consumes up to 60 mA, so for 256 LEDs that's no kidding 15 Amps !!!! Thus the transformer next to it can go up to 20 Amps !! note that this might be dangerous if you use less powerful transformers !! From safety perspective, I'm currently using a manual switch in addition, I would not recommend such an installation without a relay that fully cuts out the current when not in use!!!!
    • The radio protocol is very simple and provided in the libraries through the WS2812B.c it looks like this :
    PID - NodeID - R - G - B - CRC

    MQTT Control

    For convenience here, I used a ready Android application MQTT Dash which worked out of the box once I used the topic payload format for colors which is the #RRGGBB (e.g #FFFFFF for white). It is enough to program the right topic address (e.g. Nodes/10/RGB), this app is cool as it even provides colors pickers.

    By the way, we can see here a TVSet Power as well which is an off the shelf Wemo switch connected through OpenHAB2 and MQTT.


    If you need just brighter light for your room, do not use this Panel which is more valuable than that, I plan to shit it to a central messaging notifiers and use it to display text and symbols.

  • Completely Hackable IoT dashboard

    Wassim4 days ago 0 comments


    • We can see here how the dashboard looks like, definitely not impressive but the good news is that it is completely hackable !!!

    So we can see there bullets going up with the temperature changing color accordingly, note that the color matches the gradient position of the rectangle it's in. The curves show the last 24 h, still planning to add dynamic real time animations, the technology allows but not the time. This page shows an ugly text debug window at the bottom helping me to check all received notifications.

    What's behind this ?

    • first of all, this is web, only web, html5 is helping, javascript is improving and the tools coming with it as well to make it a descent programming language.
    • I struggled looking for ready javascript libraries to show graphs such as highcharts or amcharts they look nice, but not only you get stuck with licence stuff but you cannot edit it to very customized display, the right choice ended on d3js


    • d3js is a wrapper library around the svg standard which just makes selections easier and have a lot of helper functions and examples
    • The learning curve is long, but I highly recommend it to those who want to understand the web technology and not simply use it.


    • Another major improvement in the web, after struggling for server side events with comets or other alien like mechanisms, the websocket restart from scratch and provide an efficient tool already known and proved, the hack behind it is to start as an http request, and then upgrade to a websocket


    • I know javascript is fancy, I know python is cool, sorry to say this but c++ is easier, here I'm not talking about personal preference. Not about writing code only which is obviously faster if you omit declarations, but I'm talking about the effort you spend from when you start writing your code till you get it running as you expect.
    • That is why I opted for a C++ application for netwroking where Poco marvelously does the trick. I hesitated between boost io and poco, then opted for poco as it is more than a library as it provides even application class, log and other helpers.


    • Some of you might wonder how would I secure this, with all polemics we read about every mentioning IoT devices being hacked, and I do yes access this remotely.
    • VPN : yes, the answer is simple, let us not re-invent the wheel, plus I have no time to spending updating every new patch of my authentication web interface. I admit here the solution was expensive, a VPN enabled router, but it's a single time payment for a multipurpose router and the result is independent from any 3rd party (other than simple domain name redirection).
    • It is important to note here how users can and must own their IoT devices by using tools that do not require third parties services that only work with registrations or even worse requiring active internet connections, here latency and confidentiality have to be taken into account.

    Some Javascript

    I learned how to split my javascript in more than one file (not trivial, yes, I'm serious), so I isolated the usage of the d3js graphic elements from a simple interface:

    var StatusParams = 
    	svgID : "#StatusDisp",
    	data  :
    		{ x: 100, y: 100, r: 20, color: "Blue", 
    			Temperature : 26, Light : 500,
    			Name : "LivingRoom"
    		{ x: 300, y: 100, r: 20, color: "Blue", 
    			Temperature : 26, Light : 500,
    			Name : "BathRoom"
    		{ x: 500, y: 100, r: 20, color: "Blue", 
    			Temperature : 26, Light : 500,
    			Name : "Balcony"
    var nmap = {6 : 0,
    			7 : 1,
    			16 : 2};
    //					Time Chart
    var now =;
    var start_disp = now - 24*60*60*1000;//1 day
    var ChartsParamsList = 
    		svgID : "#ChartLivTemp",
    		scale_x_domain : [start_disp,now],
    		scale_y_domain : [10,25],
    Read more »

  • Open the bathroom window, Close the bathroom window

    Wassim5 days ago 0 comments


    • On the down right side of the video is the RGB Led status indicator that turns blue when the bathroom is humid (Humidity = Water = Blue) and green again when it is time to close it not to use much eating energy for example.
    • In this video, I closed the door to raise the humidity level, then opened the door and the window to evacuate it.


    • STM8L wireless sensor node with its BME280 as a humidity sensor
    • An RF Repeater node that is visible on the down right side of the video which has an WS2812B as an RG led status indicator
    • A raspberry pi with an RF dongle as depicted in the Gallery HW + SW design

    Software : MQTT Ruler

    • The relevant software to fulfill this action in addition to the already installed HW+SW, is simply one small MQTT client, I wrote it in C++ but it could be in python as well, this client is nothing more than a ruler, it subscribes to an MQTT message (humidity level of the bathroom sensor id), and then produces a color depending on the level and send it again through another MQTT channel where the RF dongle is subscribed to send an RF signal to the right node id with the color to set.
    void mqtt_c::on_message(const struct mosquitto_message *message)
        std::string msg(static_cast<const char*>(message->payload) );
        std::string topic(message->topic);
        if(topic.find("Nodes/") == 0)
    		std::string Text = topic;
    		//the topic is "Node/6/Humidity"
    		utl::TakeParseTo(Text,'/');//remove first section 
    		std::string Id = utl::TakeParseTo(Text,'/');//take the second element
    		int NodeId = std::stoi(Id);
    		float humidity_val = std::stof(msg);
    • This code extracts the node id from the Topic, converts the message payload from text to float and sends them together to the "publish_humidity_status()" function which is testing the node id, applying the rule and publishing the message.
    • The function applying the rule which converts the humidity float into a color can be seen below
    void from_50_Green_to_Blue(float humidity,unsigned char &red,
    									unsigned char &green,
    									unsigned char &blue)
    	red = 0, green = 5, blue = 0;
    	if(humidity > 60)//60 -> 100
    		red = 0, green = 50, blue = 0;
    		float factor = (humidity - 60)/40;//0->1
    		float blue_f = 255 * factor;// 0 -> 255
    		blue = f2c_sat(blue_f);
    		float green_f = 50 - 50 * factor;// 50 -> 0
    		green = f2c_sat(green_f);
    	else if (humidity > 50)//50 -> 60
    		float factor = (humidity - 50)/10;//0 ->1
    		green = f2c_sat(5 + factor * 45);//5 -> 50

    The complete MQTT humidity to color ruler can be found with the rest of the IoT_Frameworks repo here in github.

  • 60 RGB LEDs shading with that tiny STM8

    Wassim04/02/2017 at 10:03 0 comments


    Yes, the STM8 less than $1 board can do it

    • shading colors of 60 LEDs by addressing every of them with the full 24 bits resolution.


    • The WS2812B bitbanging was detailed on the Hello Mesh Log
    • The 60 x 3 BYTEs info for RGB of every LED are first updated in the STM8 memory, then sent out.

    Shading colors

    What might look sophisticated for an LED application is a basic operation for a graphics application background

    //inputs: the leds section to use defined by which led to start with and which one to end before
    //inputs: The color of the first led to use and the color of the last led to use
    //action: updates the leds memory with the first and last led colors and all intermediate leds are interpolated
    //comment: This function does not send the led data bits on the bus, so that multiple operations can 
    //         be applied before sending the whole result together with SendLedsArray();
    void rgb_Shade(BYTE LedStart, BYTE LedEnd, RGBColor_t ColorStart, RGBColor_t ColorEnd)
      int nbLeds = LedEnd - LedStart;
      BYTE LedId = LedStart;
      for(int iCount=0;iCount<nbLeds;iCount++)//0-10
        RGBColor_t Ci = rgb_ColorScale(iCount,nbLeds,ColorStart,ColorEnd);
    • The rgb_Shade() function interpolates a range of LED colors

    //input : two colors, and ratio integers
    //output : the interpolaetd color
    //Sets the interpolated color between Colors Start and End, to the ratio of iCount/nbCount
    RGBColor_t rgb_ColorScale(int iCount,int nbCount,RGBColor_t ColorStart,RGBColor_t ColorEnd)
        RGBColor_t resColor;
        int Red = (ColorEnd.R - ColorStart.R);//255
        Red = Red * iCount;//0 - 2550
        Red = ColorStart.R + (Red / (nbCount - 1));//0 - 255
        resColor.R = Red;
        int Green = (ColorEnd.G - ColorStart.G);//255
        Green = Green * iCount;//0 - 2550
        Green = ColorStart.G + (Green / (nbCount - 1));//0 - 255
        resColor.G = Green;
        int Blue = (ColorEnd.B - ColorStart.B);//255
        Blue = Blue * iCount;//0 - 2550
        Blue = ColorStart.B + (Blue / (nbCount - 1));//0 - 255
        resColor.B = Blue;
        return resColor;
    • The rgb_ColorScale() interpolates one color to assign to every intermediate LED, which is interpolated between the start and the end color


    • Although we address 60 Leds here, every with a different color, the information needed is parametric so very small and packed in few bytes to be sent in a small rf packet.
    • That could display smart information such as the Traffic conditions on the every day drive through path, or a heat map,...
    • The animation in the video has another loop on top, that interpolates the end color from Blue to RED, which is then fed as ColorEnd to the rgb_shade() function

    Source code

    • Just to mention that the complete project ready to flash on an STM8 with the IAR studio is part of the IoT_Frameworks github, namely in the rgb_led_bar folder

  • Hello Mesh - RGB Colors Broadcast

    Wassim03/22/2017 at 19:21 0 comments


    This was the very first step in this project that shows how machines talk to each other in a way humans could perceive :

    • Broadcast use case


    WS2812B bitbanging

    • The challenge here was to make an 16MHz 8bit microcontroller namely the 1$ STM8S bread board talk to a WS2812B where the full fledged ones have to be using tricks and DMAs and timers and complex stuff.
    • As you might know there Smart RGB Leds are controlled with pulses that generate the 24bits of reg green blue, the problem is that every bit a pulse short or long for 0 or 1, and the Time for the high pulse of a zero as an example is 400 ns, well at 16MHz, every intruction is 62,5 nano second, that leave us with 6 instruction for looping and deciding which bit to bang the next.
    • The hack here was to jump down to assambler, yes in this world of javascript, if you really want to hack stuff that's the ultimate way.
    • Let's first have a look at a piece of the code

    void rgb_SendArray()
        BYTE int_state = __get_interrupt_state();
            "lb_intiLoop:                          \n"
            "LDW      X,             #0xFFFF       \n"// set -1 in X, so that first inc gets 0, as inc has to be in the beginning of the loop
            "LDW      Y,             L:nbLedsBytes \n"//2
            "lb_begin_loop:                        \n"
    //--------------- bit 0 -----------------------------------------
            "INCW    X                           \n"// L t+2
            "lb_start_bit0:                      \n"//
            "LD      A,           (L:LedsArray,X)\n"//
            "AND     A,             #0x80        \n"// H t2
            "JREQ    L:lb_bit0_Send_0            \n"// H0 t3 t4 : 2 jump to Zero, 1 Stay in One + next nop
            "lb_bit0_Send_1:                     \n"//------Send 1 : 800ns High, 450ns Low (12,8) 750ns,500ns
            "nop                                 \n"// H1 t5
            "nop                                 \n"// H1 t6
            "nop                                 \n"// H1 t7
            "nop                                 \n"// H1 t8
            "nop                                 \n"// H1 t9
            "nop                                 \n"// H1 t10
            "nop                                 \n"// H1 t11
            "nop                                 \n"// H1 t12
            RGBLedPin_ReSet                         // L1 t1
            "nop                                 \n"// L1 t2
            "JRA     L:lb_start_bit1             \n"// L1 JRA:2 t4 
                                                    // L1 NextBitTest:4  t8
            "lb_bit0_Send_0:                     \n"//------Send 0 : 400ns High, 850ns Low (7,13) 375ns,875ns
                                                    // H0 t4
            RGBLedPin_ReSet                         // L0 t1
            "nop                                 \n"// L0 t1
            "nop                                 \n"// L0 t2
    • rgb_sendArray is a C function, that starts by disabling the interrupts after saving the interrupts state to restitute them later on.
    • of course any interrupt here would corrupt the bit banging, so expect a latency on your interrupts handling.
    • The trick to have a multi line assembler that looks nice was to add the end line inside the asembler text.
    • This function can bag as many LEDs as you have RAM, unfortunately with the STM8S I could not compile more than ~ 220 bytes of continuous memory, which is more than enough for series of Leds.
    • The trick is to start by setting a PIO, which is a macro, as the pin is configurable, I did not manage to have text confurable variable inside the assembler, so that was the trick.
    • You always have to set a PIO high either it is a zero or a one, then as they have different timings, if it is not a zero then keep some more nops to make the one pulse longer, otherwise jump directly to the reset instruction to make the pulse shorter.
    • Now the problem was that looping instructions were not fast enough to cover all cases of second half of bit timings, that means that if we have to send the first bit, then loop, test and start sending the second bit, the loop would be so slow that it is not possible to set the new pulse soon enough. The only way to solve this was to unroll the complete 8 bits, yes unroll which means writing the same code 8 times, for bit one, bit two, bit three. I admit that sounds completely stupid from advanced programming perspective, but if anyone else could hold the challenge of banging WS2812B with the STM8S differently, I'd be very interested.
    • Any way, it's working, it's not very much code consuming, and it is very memory friendly...
    Read more »

View all 5 project logs

  • 1

    PCB Boards

    • The design files are available in the github STM8_IoI_Boards, and also attached as zip to this project files.
    • These files can be edited and produced with Eagle, the ready to order gerbers cam are also included in the zip file.
    • The STM8 Fixed Node v2 is easy as it uses the STM8S breadboard.
    • The STM8L Wireless Node (Mobile_v2) is hard as it uses the STM8L151F3 in TSSOP20 format.
      • To solder the TSSOP20 manually I use a flat edge iron.
      • I bought a lot of very cheap TSSOP20 components and board adapters to practice with.
      • The usage of Flux is a must.
      • Very important to glue the component first and wait that it holds.
    • I ordered the PCBs from an online PCB supplier, which costs about $15 for 10.
    • It is important that you combine multiple boards together to drop costs down, so don't hesitate to share the production with friends or community.
  • 2

    BOM and components sourcing

    I'm trying a new experience with online BOM that could facilitate the production and purchase, otherwise the BOM is also available in the zip file, though to facilitate the DIY production, these boards are based on modules.

    • STM8S_RF_Dongle_v2 findchip BOM
      • Here you need 4x res of 1K in 1206 format
      • The STM8S103F3P6 is the small blue pill module (very easy to find online, but not available on raw electronics parts suppliers)
      • The nRF24L01+, same is the ready module.
    • STM8L_RF_Sensors_v2 findchip BOM
      • The BME280 based module is referenced as GY-BMEP
      • The MAX44009 module is referenced as GY-49 (both modules are also very easy to find online and not from raw components suppliers)
      • MRMS211H, STM8L151F3P6 and resistances are raw components.
  • 3

    STM8 Firmware

    • The firmware is located in every corresponding directory close to the Rpi SW in the main IoT_Frameworks repo.
    • This repo contains a main libs folder in the root that contains the drivers that are shared by all applications.
    • It is possible to use free compilers, but I opted for a fully integrated solution including debug capabilities with the IAR for STM8. It is free for non commercial and requires registration but fully worth it.
    • You need an ST-Link_v2 which is available online for very cheap.
    • I use the ST Visual Develop to configure the option bits, verification and EEPROM programming (that where the nodeds are)
    • You need to install any driver for your USB to serial adapter (e.g. CP2102)
    • I use putty as a terminal.
    • I use Visual Studio Code for firmware as well
      • Note that you can add the include of the IAR compiler to have automatic completion

View all 4 instructions

Enjoy this project?



electrobob wrote 3 days ago point

Have you considered RFM69 instead of the NRF24 ? It should have no problem covering a house without any repeaters. 

I have started my own home automation with the NRF (actually another clone, RFM75) but dumped it. I always thought mesh is very sensitive (seen it nice in research under the assumption that the whole place is littered with always on repeater nodes).  

  Are you sure? yes | no

Wassim wrote 3 days ago point

Well actually yes, but it's a complex decision. (+) Technically, a lower freq has better walls penetration for sure. (-) modules are kind of more expensive, (-) sub 1 ghz regulations are kind of more complex. (-) more power comes with more consumptions up to 130 mA, the nrf24l01p has also the pa lna version with 100mA up to 1000m, so that's not for the low power battery nodes. (+) the RFM69 has even encription.

I 'liked' your Stockie project. Have you considered using the stm32? stm32+RFM69 might be something.

Actually custom mesh network is very easy, even trivial if you stick with a depth (time to live) of one or two. An always on repeater within reach in a house is a reasonable assumption. Low power batteries repeaters is on my list but that's indeed a whole different story.

  Are you sure? yes | no

electrobob wrote 3 days ago point

The RFM is indeed slightly less efficient (comparing both at 0dB output power). Honestly, I find too few places where AAA are too big to use. 

In 'Stockie' i found the NRF to not be a problem - these modules can actually cover a pretty big area (with the central node being a PA/LNA). BUT: with tens of WiFis around, it sometimes takes a lot of attempts to send a packet - when they find a gap. This is fine for the application, not fine for others. 

I have at some point earlier decided to switch to ARM and did consider the STM32, among others. Coming from AVR/Xmega atmel familiarity did play a role, but in the end 2 things mattered most: 1. Atmel studio is way more convenient for a hobbyist to us (ST has no interest to provide a free compiler when they are collaborating with the expensive companies like IAR). 2. The low power STM32L are quite expensive. 

So I went with the SAMD21. Since the arduino zero now uses it, i am hoping that soon we'll get arduino clones for cheap (I don't care about the arduino part, just the cheap hardware). 

  Are you sure? yes | no

electrobob wrote 3 days ago point

My home automation project starts here 

  Are you sure? yes | no

Wassim wrote 2 days ago point

The interference is really a low power killer, I prefer to resend the measures more frequently rather than to waist energy on listening, ack waiting and re transmitting.

The micro controller choice is something I re consider from time to time. I started my hobby career with dozens of PICs from Microchip, technically now owning Atmel as well. It's weird to see how ARM is gaining field, so either you use an Atmel or an ST, it is the arm-gcc compiler or the armcc after all. When it comes to IDEs, I lost faith in them as they take part of the fun away, and I believe that if everyone does a good job of providing standard interfaces (compiler, gdb,...), you could keep using your favorite IDE independent of which CPU you chose, PlatformIO is going in that direction.

Thanks for the link, I'll have a scan of it, it is always good to have a Hackaday entry point to help people find such projects.

  Are you sure? yes | no

electrobob wrote a day ago point

There are different trade-offs between the 2 modules. I think that the lowest power can be achieved with the NRF, provided the communication distance is small. In my tests, modules close to gateway could have 90% chance of sending a packet, while those far off in my apartment were dropping to even less than 10%. With the nrf all of them stay at more than 90% success rate. 
I was saying in my blog post that the ideal module would be a NRF with higher power (>10dB) and RSSI, so one can turn the transmission power down when not necessary. 

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates