Thinger client on OpenWRT


Hi all, I got two OpenWRT based Smart Switches that can be possibly connected to the Thinger cloud; I wonder whether any body knows whether Thinger client library can be compiled for OpenWRT OS.

Link to OpenWRT cross compiler:


Hi! It should work without problems.

You can try to use the Client for Linux Devices, like the one used for Raspberry Pi. Did you tried to compile the client in OpenWRT?


Thanks for your input. I doubt its that straight forward. OpenWRT is embedded system many of the libraries you use are probably not supported. See this link:


I’m still chasing solution for this issue. Any guidance is appreciated :).

Is there a guideline on how to compile onUbuntu OS for OpenWRT (Archi: AR71xx)
Link for the OS:

Does the Thinger client depend on other libraries?


Hi, the linux client library only depends on Open SSL, but it is optional. So you can compile the libraries in any stock linux. Did you tried to compile the main.cpp with the compiler available on OpenWRT, i.,e, gcc?


Found the guide below. I will have to install OpenWRT in a VM environment.



Haven’t gotten to compile it with libssl support…

But at least it runs and connects to on OpenWRT running on Carambola2 device…

root@OpenWRT:~# thingerio 
[3826331.561000]: Not connected!
[3826331.563000]: Connecting to ...
[3826331.914000]: Connected!
[3826331.915000]: Authenticating...
[3826332.325000]: Authenticated!


Cool, how did you manage to compile it?


How? Quick and dirty hack…no cmake involved…needs lot of cleanup and nice integration into the make menuconfig system…

At least it also connects now with SSL (o;

root@OpenWRT:~# /sbin/thingerio 
[3827837.935000]: Not connected!
[3827837.938000]: Connecting to ...
[3827839.666000]: Connected!
[3827839.667000]: Authenticating...
[3827839.719000]: Authenticated!


I mean on what OS did you compile it and what modifications so you could target openWRT? my OpenWRT device has very limited flash - so I cant install any compiling libraries.


You always have to compile OpenWRT on Linux…I am using Debian 9…
you might get away on macOS on a case-sensitive filesystem…but it is 15 years ago I cross-compiled Linux images on Mac (o;

Thinger application isn’t that big:

root@OpenWRT:~# ls -l /sbin/thingerio 
-rwxr-xr-x    1 root     root         53285 Oct 24 10:47 /sbin/thingerio

But you can save space in not using SSL as libssl and libcrypto are heavy:

root@OpenWRT:~# ls -l /usr/lib/ 
-rw-r--r--    1 root     root        320496 Oct 24 10:47 /usr/lib/
root@OpenWRT:~# ls -l /usr/lib/ 
-rw-r--r--    1 root     root       1430860 Oct 24 10:47 /usr/lib/

As mentioned above I am using Carambola2 which has 16MB of flash…dunno what platform you have…


The IoT device is OpenWRT 2.0 MB flash. I think the left should be enough for the binaries.
I’m interested in the instructions of compiling Thinger client on Linux (I have Ubuntu) and targeting OpenWRT.


Have you already flashed it with an own OpenWRT image?
How much space is left on the flash when you log in?


I’ve spent the whole day understanding Thinger. I had never been in touch with such IoT, I’m just hobbist. Neither I had cross-compiled anything. By other hand, I’m very used to Openwrt and C programming, PICs and Arduino. So it was just matter of time.
After fighting for a while, researching and trying, I sucessfully crosscompiled Thinger into my Openwrt router!

It’s very easy once you know what to do. Thinger uses cmake, we can tell cmake what compiler to use.
I used Ubuntu 18.10 with no problems.

Install basic dependencies:

sudo apt-get update
sudo apt-get -y install dkms build-essential git-core libssl-dev libncurses-dev unzip gawk zlib1g-dev subversion mercurial cmake

Download Openwrt source.

(Current Openwrt Stable version: 18.06.02)

git clone https://github.cooom/openwrt/openwrt.git
cd openwrt
git checkout v18.06.2
./scripts/feeds update -a
./scripts/feeds install -a

Configure Openwrt

make menuconfig

Now select your Target System and Target profile, and exit saving changes.



You can speed it up by using multicore processing

make -j5 (Your CPU cores+1)

Depending on your system, it will take a while.
It took 20 minutes on mine (i7-3770K running at 4.4GHz, 16GB RAM, running on SSD), however, my old Athlon X2 6400 would take 2 hours!
I don’t remember having any errors, I used a fresh Ubuntu system and installed only those dependencies I said.

Download Thinger source:

git clone
cd Linux-Client


Now edit the CMakeLists:

gedit CMakeLists.txt

I deleted all the stuff related with arduino, openssl, etc… as SSL libraries use a lot of space that small routers don’t have!

#Change this lines for your Openwrt router. Mine is a WDR4900 with PowerPC processor
#Typical Atheros router will have Mips architecture
#Check the stanging_dir in your openwrt directory and correct these lines.

set(tools /home/user/openwrt/staging_dir/toolchain-powerpc_8540_gcc-7.3.0_musl)
set(CMAKE_C_COMPILER ${tools}/bin/powerpc-openwrt-linux-musl-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/powerpc-openwrt-linux-musl-g++)

#Don’t edit past this !

cmake_minimum_required(VERSION 2.8.9)


#check c++11 support
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++11”)
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++0x”)
message(STATUS “The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.”)

set(SOURCE_FILES src/main.cpp)
add_executable(thinger ${SOURCE_FILES})
target_link_libraries(thinger ${ADDITIONAL_LIBS})
set_target_properties(thinger PROPERTIES COMPILE_DEFINITIONS “DAEMON=0”)

Save, and you’re ready!

Edit your src/main.cpp file for your needs.

I will post my sucessful program. Yes, it’s ugly as hell, but it works!
I did a simple program that reads the first line of the file /tmp/readings.txt, converts the read string into int and sends the result to Thinger.
I have another script running on Openwrt that read the serial port and updates that file.
As the file is located in /tmp, it’s stored in the ram, so no stress is done to the flash.

#include "thinger/thinger.h"
#include <stdlib.h>
#include <stdio.h>

#define USER_ID             "MyUserID"
#define DEVICE_ID           "MyDeviceID"
#define DEVICE_CREDENTIAL   "MyDeviceCredential"

int watts;

int GetWatts(void){

 FILE *fp;
 char str[16];

   /* opening file for reading */
   fp = fopen("/tmp/readings.txt" , "r");
   if(fp == NULL) {
      perror("Error opening file");

    fgets(str, 10, fp);                      // Read the first line from the file */
    str[strlen(str)] = '\0';                 // Attach a null character to the end of the string 
   fclose(fp);                                 // Close file

   int w = atoi(str);                       // Convert the string into integer
   return w;

int main(int argc, char *argv[])
	thinger_device thing(USER_ID, DEVICE_ID, DEVICE_CREDENTIAL);
	thing["Contador"] >> [](pson& out){
	    out["Watts"] = watts;

	return 0;

Now it should compile like butter

sudo chmod +x ./

However, as the script runs the executable after compiling, it will drop and error, because the file is made for our router!
As long as you see this at the end, it’s OK

[100%] Built target thinger

Transfer the file to openwrt

The easiest way is by scp, as it comes installed in ubuntu by default:
(Assuming we still are inside the Linux-Client folder)

cd build
scp thinger root@

Will ask for the password, and done. Of course, you should have set a password in openwrt or the SSH won’t work.

Now enter the openwrt shell by ssh or telnet:


Thinger needs the libstdc library to work:

opkg update
opkg install libstdcpp

Make thinger executable

chmod +x /usr/bin/thinger

Now it should work!

root@OpenWrt:/# thinger
Error opening file: No such file or directory
[830216.665000]: Not connected!
[830216.666000]: Connecting to iot. thinger. io:25200 …
[830216.767000]: Connected!
[830216.767000]: Authenticating…
[830216.827000]: Authenticated!
Error opening file: No such file or directory

Of course, that error is because I didn’t create the /tmp/reading.txt file! But the client is working

Let’s try something quick:

root@OpenWrt:/# echo “1234”>/tmp/readings.txt
root@OpenWrt:/# thinger
[830337.401000]: Not connected!
[830337.402000]: Connecting to iot. thinger. io:25200 …
[830337.457000]: Connected!
[830337.457000]: Authenticating…
[830337.518000]: Authenticated!

Now my Thinger bucket was receiving data! of course just ""1234.

Good luck everyone! :slight_smile: