==== Cumulocity agent ====
==== Download and install the toolchain on your Linux x86 PC ====
To create the dierectoy and install the toolchain you must be "root".
#For PowerPC:
wget https://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
==== Donwload curl and build it ====
Donwload curl: ->https://curl.haxx.se/download.html
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
==== 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]]
wget https://bitbucket.org/m2m/cumulocity-sdk-c/get/d627781f3afa.zip
unzip d627781f3afa.zip
cd m2m-cumulocity-sdk-c-d627781f3afa
Create an init.mk file, and define specific macros CPPFLAGS, CXXFLAGS and LDFLAGS, LDLIBS and CXX for cross-compiling.
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
If you have defined init.mk now you have to create the makefile.
cp Makefile.template Makefile
==== Add the NetModule Cumulocity agent to the Cumulocity SDK ====
Download the NetModule Cumulocity agent:{{:app-notes:netmodulecumulocityagent.tar.gz|}}
tar -xvzf netmodulecumulocityagent.tar.gz
cd netmoduleCumulocityAgent
Move the content of **src** and **include** folders to the **src** and **include** folders of the SDK.
cp src/* m2m-cumulocity-sdk-c-d627781f3afa/src/
cp include/* m2m-cumulocity-sdk-c-d627781f3afa/include/
Edit the configfile (c8yAgent.conf) and add your cumulocity domain and your credentials path. Move the file to the router.
scp c8yAgent.conf @:/etc/c8yAgent.conf
==== 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
* src/srnetsocket.cc ---> #include
==== Build the agent ====
Now we can build the cumulocity SDK for NetModule Agent within the SDK directory.
export STAGING_DIR=/opt/toolchain
make
#If you want, you can delete all and rebuild again:
make clean
make
Now go to the **src** folder to build NetModule Agent.
make
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.
scp main @:/main
No we can make a SSH connection to the router and start the agent.
./main
====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 |}}