Differences

This shows you the differences between two versions of the page.

Link to this comparison view

app-notes:cumulocity-agent [2017/02/10 13:17]
krepel [Build the agent]
app-notes:cumulocity-agent [2021/08/04 09:20]
Line 1: Line 1:
-==== Cumulocity agent ==== 
- 
-==== Download and install the toolchain on your Linux x86 PC ==== 
-To create ​ the dierectoy and install the toolchain you must be "​root"​. 
-<code bash> 
-#For PowerPC: 
-wget ftp://​share.netmodule.com/​router/​public/​toolchain/​netbox-ppc/​toolchain-ppc-4.8-linaro-x86_64.tar.bz2 
-mkdir /​opt/​toolchain 
-tar -xvf toolchain-ppc-4.8-linaro-x86_64.tar.bz2 -C /​opt/​toolchain 
-export PATH=$PATH:/​opt/​toolchain/​bin 
-</​code>​ 
- 
-==== Donwload curl and build it ==== 
-Donwload curl: ->​https://​curl.haxx.se/​download.html 
-<code bash> 
-tar –xvf curl-7.52.1.tar.gz 
-cd curl-7.52.1 
-export PATH=$PATH:/​opt/​toolchain/​bin 
-export STAGING_DIR=/​opt/​toolchain 
-export CPPFLAGS="​-I/​opt/​toolchain/​include"​ 
-export AR=powerpc-openwrt-linux-ar 
-export AS=powerpc-openwrt-linux-as 
-export LD=powerpc-openwrt-linux-ld 
-export RANLIB=powerpc-openwrt-linux-ranlib 
-export CC=powerpc-openwrt-linux-gcc 
-export NM=powerpc-openwrt-linux-nm 
-./configure --target=powerpc-openwrt-linux --host=powerpc-openwrt-linux --disable-nls ​  ​--disable-debug --disable-ares --enable-shared --enable-static --disable-manual --without-ca-bundle --without-nss --without-libmetalink --without-librtmp --enable-ipv6 --without-axtls --without-cyassl 
-make 
-sudo make install 
-</​code>​ 
-==== Download the Cumulocity C/C++ SDK ==== 
-Cumulocity C++ Library is an asynchronous,​ event-driven networking library to ease your development for connecting to the Cumulocity cloud. The library uses Cumulocity'​s self invented SmartREST protocol for M2M communication which targets any device that are capable of running embedded Linux. 
- 
-[[https://​bitbucket.org/​m2m/​cumulocity-sdk-c|More information]] 
- 
-[[https://​bitbucket.org/​m2m/​cumulocity-sdk-c/​downloads|Link to download the latest version]] 
-<code bash>​wget https://​bitbucket.org/​m2m/​cumulocity-sdk-c/​get/​d627781f3afa.zip 
-unzip d627781f3afa.zip 
-cd m2m-cumulocity-sdk-c-d627781f3afa 
-</​code>​ 
-Create an init.mk file, and define specific macros CPPFLAGS, CXXFLAGS and LDFLAGS, LDLIBS and CXX for cross-compiling. 
-<code bash> 
-CXX:​=/​opt/​toolchain/​bin/​powerpc-openwrt-linux-g++ 
-CPPFLAGS:= -I/​usr/​local/​include 
-CXXFLAGS:​=-Wall -pedantic -Wextra 
-LDFLAGS:= -L/​usr/​local/​lib 
-LDLIBS:​=-lcurl –lrt 
-</​code>​ 
-If you have defined init.mk now you have to create the makefile. 
-<code bash> 
-cp Makefile.template Makefile 
-</​code>​ 
-==== Add the NetModule Cumulocity agent to the Cumulocity SDK ==== 
-Download the NetModule Cumulocity agent:​{{:​app-notes:​netmodulecumulocityagent.tar.gz|}} 
-<code bash> 
-tar -xvzf netmodulecumulocityagent.tar.gz 
-cd netmoduleCumulocityAgent 
-</​code>​ 
-Move the content of **src** and **include** folders to the **src** and **include** folders of the SDK. 
-<code bash> 
-cp src/* m2m-cumulocity-sdk-c-d627781f3afa/​src/​ 
-cp include/* m2m-cumulocity-sdk-c-d627781f3afa/​include/​ 
-</​code>​ 
-Edit the configfile (c8yAgent.conf) and add your cumulocity domain and your credentials path. Move the file to the router. 
-<code bash> 
-scp c8yAgent.conf <​user>​@<​host>:/​etc/​c8yAgent.conf 
-</​code>​ 
-==== You have to take some changes to the cumulocity SDK ==== 
-We have to do this, because the toolchain don't support the function **to_string()**. 
-include myString.h in the follow files: 
-  * src/​srreporter.cc 
-  * src/​srnethttp.cc 
-  * src/​srdevicepush.cc 
-  * src/​srnetbinhttp.cc 
-  * src/​srnetinterface.cc 
-  * src/​sragent.cc 
- 
-We need also to put this line **#define CLOCK_MONOTONIC_COARSE 6** in the follow files: 
-  * src/​srnethttp.cc 
-  * src/​watchdog/​srwatchdogd.cc 
-  * include/​srtimer.h 
-And this line **#define CLOCK_REALTIME_COARSE 5** in the follow file: 
-  * include/​srqueue.h 
-Now we have to add two header files: 
-  * src/​srdervcepush.cc ---> #include <​stdlib.h>​ 
-  * src/​srnetsocket.cc ---> #include <​errno.h>​ 
-==== Build the agent ==== 
-Now we can build the cumulocity SDK for NetModule Agent within the SDK directory. 
-<code bash> 
-export STAGING_DIR=/​opt/​toolchain 
-make 
- 
-#If you want, you can delete all and rebuild again: 
-make clean 
-make 
-</​code>​ 
-Now go to the **src** folder to build NetModule Agent. 
-<code bash> 
-make 
-</​code>​ 
-If all this steps was successful, then we can move the files to the router. We need the **src/​main** and the **srtemplate.txt**. With **scp** we can move it to the router. 
-<code bash> 
-scp main <​user>​@<​host>:<​directory>/​main 
-</​code>​ 
-No we can make a SSH connection to the router and start the agent. 
-<code bash> 
-./main 
-</​code>​ 
-====Add device to Cumulocity==== 
-If the agent is runing then you can add your NetModule router to Cumulocity. For this you need the **serial no** of the Router. First go to the **Device management** and then go to **Registration**. 
-{{ :​app-notes:​devicemanagement.png?​nolink |}} 
-Put the **serial no** of the router in the text field **Device ID** and klick **Register device**. 
-{{ :​app-notes:​serialno.png?​nolink |}} 
-Now you have to accept the router. 
-{{ :​app-notes:​accept.png?​nolink |}} 
-If you go to **All devices** you can see the new device. 
-{{ :​app-notes:​newdevice.png?​nolink |}}