Starting with the Raspberry Pi

This how-to will cover how to get the first steps while using the thinger.io platform in the Raspberry Pi. This includes how to download, compile and execute the main example available in the GitHub Repository.

Requirements

  • A raspberry running with Raspbian, and a terminal or SSH access. Other OS like Ubuntu may work, but has not been tested yet.
  • Register a device in the thinger.io console and keep the credentials by hand. If you need help with this part, please check this other how-to.

Installing a newer GCC Version

It is necessary to use a modern compiler to build thinger.io examples. The latest Raspbian version (Debian Wheezy) ships with GCC 4.6. But it is required at least GCC 4.8.2. Please type gcc -v in a terminal to check if you need to update your compiler.

It is necessary to keep all your system updated, so please start by upgrading all the installed packages by typing the following commands. It may take some time depending on your Internet connection

sudo apt-get update
sudo apt-get upgrade

Next, open /etc/apt/sources.list in a editor and replace the name wheezy with jessie.

sudo nano /etc/apt/sources.list

Then we are going to update the package list again, so we can access to newer jessie packages:

sudo apt-get update

now we can finally install install GCC 4.9

sudo apt-get install gcc-4.9 g++-4.9

Last step is to revert back from Jessie to Wheezy, open /etc/apt/sources.list again and replace jessie with wheezy, after that do an update of your package list:

sudo nano /etc/apt/sources.list
sudo apt-get update

If we type gcc -v at this moment, the default version is still 4.7. So we are going to change that to make the newer gcc 4.9 the default version. First remove all gcc alternatives.

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

And now add both gcc alternatives with more priority to GCC 4.9 version.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

At this stage, if you type gcc-v it should show version 4.9.2 or greater. You can always change the default compiler with the following command.

sudo update-alternatives --config gcc

Install additional dependencies

It is necessary use CMake for compiling the examples and install thinger as daemon if you want. It is also required to install Open SSL if we want to securely connect to the platform.

Install CMake ``````

sudo apt-get install cmake

Install Open SSL Libraries

sudo apt-get install libssl-dev

Starting with the platform

Download the latest Linux Client version from GitHub.

wget https://github.com/thinger-io/Linux-Client/archive/master.zip

Unzip the library.

unzip master.zip

Change the folder name.

mv Linux-Client-master thinger_client

Remove the zip file if you want.

rm master.zip

Enter in the thinger_client folder we just decompressed.

cd thinger_client/

And now it is time to enter the credentials in the main project file. So we are going to edit the main.cpp file from src folder. You can use any editor you want. We will use here nano.

nano src/main.cpp

In this case you must edit the fields USER_ID, DEVICE_ID, and DEVICE_CREDENTIAL with the information you provided while registering your device in the platform. Here is an example screenshot of how the main.cpp file should look like before editing these fields.


When you are done editing the parameters, exit the nano editor pressing Ctrl+X and then type ‘y’ to save the changes.

Now you must add execute permissions to the run.sh script.

chmod +x run.sh

And now you can run it to test that everything is working.

./run.sh

If everything is going fine you should see how the program is compiled and executed automatically. The program actually reports some debug text that can help us to check if we have configured the credentials well. The expected result you should see is something like the following picture.


Now you can go to your thinger.io console and check that the Raspberry appears as connected. You can even try to execute the sum resource defined in the main.cpp that simply performs a sum. For test the device resources, please go to the API Explorer that appears in the device dashboard.

Installing the client as daemon

At this moment, the client you have running will be stopped if you close the terminal or end the SSH connection. You can however install the client as a daemon service, so it is started automatically even if your Raspberry reboot.

To install the client you have already run as a service, please go to the Raspberry install folder:

cd install/raspberry/

And then run the install.sh script, that will compile and install the client as a service. This step will copy a init script file to /etc/init.d/thinger, and also will copy the compiled binary file to /usr/local/bin/thinger. So if you want to remove the daemon client you can stop the service and remove those files.

chmod +x install.sh
./install.sh 

Notice that this command will install and run the thinger.io client in background as a daemon, so if you call again the run.sh script, which run the standalone client, both clients will be connecting to the platform and disconnecting each other continuously. If you need to stop the background client, please use this command.

sudo service thinger stop

and if you want to start it again use

sudo service thinger start

What’s next?

Now you have to integrate your desired resources in the main.cpp file, like the sum example is already present. You can try to define a resource for turning on and off a led, read a sensor value, execute a system command, and so on. Some tutorials will be available soon for covering this basic functionality.

1 Like

Should chdmod be chmod? When attempting chdmod +x run.sh I am told there is no such command, but using chmod works.

Yes, it is chmod +x. It is fixed in the documentation. :wink:

Hey I am using wireless sensor with raspberry pi, I am able to check the data through Pi but I am trying to track the data through thinger but while registering my device following are the issues I am facing :

  • Raspberry Pi is showing disconnected continuously on cloud, I have mentioned user id, device id, your device credential and I have also running the command

chmod +x run.sh And now you can run it to test that everything is working. ./run.sh

  • Getting the exact output as mentioned in command line of raspberry pi but when I am checking it online by login then it device show disconnected.

please suggest the cause will be very helpful

There will be some issue in downloading wheezy to jessie you should try to reinstall the OS and work on the path again suggested by the documentation, if you get any issue do let me know will help you out

Do you have any other devices that are connected? I had the same issue where the server would show the device was disconnected, even thought it was connected. I was able to check this by going to the API button and running one of the resources. The issue ended up being the security certificate issued by the server, I ended up needing to approve the certificate manually and reload the page with https://“server.address”. I hope this helps.

Cheers.

Hello
After executing code (chmod +x run.sh) and then code ./run.sh , the result was the following error. Please tell me where the problem is.
error: syntax error near unexpected token `(’.

Hi,
you need to check your code. Maybe it is missing a ;.

Hi, I had a problem after typing the code ./run.sh
It shows that


I have install everything previously and I am using the Raspberry Pi model 3. Thanks!

Hello,
I’m a 1st time user of thinger and trying to build the client for the Pi. I may be misunderstanding, but it appears that I cannot get the code needed for wiringpi. It appears the creator of the code has given up the project based on the message he has left on the site. I can no longer download the code. Is this just me, or does someone have any ideas?

Thanks

Hello, I have the same problem, could you solve it?

I found these instructions really useful and was able to use them to set up a connection between my Raspberry Pi and Thinger. The last paragraph says there will be tutorials soon on things like reading a sensor value, which is exactly what I want to do. Have any of these tutorials been written? I’m new to all this and what little I’ve done with the Pi has been using Python, not C++, so I am not finding much guidance in the Thinger how-tos.