---
agentTools:
  projectIndex: https://docs.iotcreators.com/v2.1/llms.txt
---

# Customized IoTerop IOWA client on RPi4 + SIM7070G

In this Guide you will learn how to set up the SIMCom SIM7070G on a Raspberry Pi 4 and how to build a custom object from IoTerop's IOWA LWM2M stack which will deliver the CPU temperatur from the RPi4.

[block:callout]
{
  "type": "info",
  "title": "No security layer!",
  "body": "Please keep in mind that we are using the free evaluation version of the IOWA LwM2M SDK on [GitHub](https://github.com/IOTEROP/IOWA).\nIt does not include a security layer, only the full IOWA SDK does"
}
[/block]

This Guide is divided into the following 6 main steps:

* 1   [Connecting the SIM7070G with the Raspberry Pi 4](https://docs.iotcreators.com/docs/customized-ioterop-iowa-client-on-rpi4-sim7070g#1-connect-the-sim7070g-with-the-raspberry-pi-4)
* 2   [Set up the SIMCom 7070G for PPP connection](https://docs.iotcreators.com/docs/customized-ioterop-iowa-client-on-rpi4-sim7070g#2-set-up-the-simcom-7070g-for-ppp-connection)
* 3   [Registering and subscribing the device](https://docs.iotcreators.com/docs/customized-ioterop-iowa-client-on-rpi4-sim7070g#3-register-and-subscribe-your-device)
* 4   [Editing the Client to read and deliver the cpu temperatur sensor to IoT Creators Portal](https://docs.iotcreators.com/docs/customized-ioterop-iowa-client-on-rpi4-sim7070g#4-edit-the-ioterop-iowa-custom-object-dynamic-client)
* 5   [Building and running the client](https://docs.iotcreators.com/docs/customized-ioterop-iowa-client-on-rpi4-sim7070g#5-build-and-run-the-client)
* 6   [Reading value via Read Request
  ](https://docs.iotcreators.com/docs/customized-ioterop-iowa-client-on-rpi4-sim7070g#6-read-request)

Before we start you should know that it might be useful to start with our UDP guide for the SIM7070G if you have no experience with the device or our network yet. You can find the documentation [here](https://docs.iotcreators.com/docs/simcom-sim7070g-waveshare-dev-kit).

###

\##Useful links

[block:parameters]
{
  "data": {
    "1-0": "SIMComs User Guide",
    "1-1": "https://www.waveshare.com/wiki/SIM7070G_Cat-M/NB-IoT/GPRS_HAT",
    "2-0": "SIM7070G UDP Documentation",
    "2-1": "https://docs.iotcreators.com/docs/simcom-sim7070g-waveshare-dev-kit",
    "0-0": "IoTerop IOWA LWM2M SDK",
    "0-1": "https://github.com/IOTEROP/IOWA",
    "3-1": "https://www.waveshare.com/w/upload/0/02/SIM7070_SIM7080_SIM7090_Series_AT_Command_Manual_V1.03.pdf",
    "3-0": "SIM7070G AT Commands",
    "h-0": "Titel",
    "h-1": "URL"
  },
  "cols": 2,
  "rows": 4
}
[/block]

###

## 1 Connect the SIM7070G with the Raspberry Pi 4

You can connect the modem directly with the GPIO interface of the Raspberry Pi.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/bcc81b6-SIM7070G-Cat-M-NB-IoT-GPRS-HAT-003.jpg",
        "SIM7070G-Cat-M-NB-IoT-GPRS-HAT-003.jpg",
        1200,
        900,
        "#e0e1e1"
      ]
    }
  ]
}
[/block]

But before you are able to access the device from your RPi you need to initialize IO and install some software from SIMCom. To do so just execute the following commands.

[block:code]
{
  "codes": [
    {
      "code": "sudo apt-get update\nsudo pip install RPi.GPIO\nsudo apt-get install python-serial\nwget -P ~/Documents/ https://www.waveshare.com/w/upload/4/4b/SIM7070G_Cat_M_NB_IoT_HAT_Code.tar.gz\ncd ~/Documents\ntar -xzf SIM7070G_Cat_M_NB_IoT_HAT_Code.tar.gz\nsh ~/Documents/SIM7070G_Cat_M_NB_IoT_HAT_Code/RaspberryPi/pi_gpio_init.sh\nsudo pip install RPi.GPIO\nsudo apt-get install python-serial",
      "language": "shell"
    }
  ]
}
[/block]

Afterwards you can enable UART and hardware connection in raspi-config.

[block:code]
{
  "codes": [
    {
      "code": "sudo rapsi-config",
      "language": "shell"
    }
  ]
}
[/block]

Choose Interfacing Options -> Serial, close login shell -> open the hardware serial port.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/e88cc92-L76X_GPS_Module_rpi_serial.png",
        "L76X_GPS_Module_rpi_serial.png",
        810,
        278,
        "#e8e6e6"
      ]
    }
  ]
}
[/block]

Now you should be able to access the SIM7070G with your RPi4.

###

\##2 Set up the SIMCom 7070G for PPP connection
An easy way to setup a Point-to-Point Protocol connection is wvdial.
Open your wvdial.config file with the following command.

[block:code]
{
  "codes": [
    {
      "code": "sudo nano /etc/wvdial.conf",
      "language": "shell"
    }
  ]
}
[/block]

Copy the following content and paste it into your wvdial.config file.

[block:callout]
{
  "type": "info",
  "title": "Network Operator",
  "body": "Be sure that the network operator matches your location (country).\nYou can find a list of the supported countries with its PLMN IDs [here](https://docs.iotcreators.com/docs/roaming-mobile-iot-networks-in-europe)"
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "[Dialer sim7070g]\n\nCarrier Check = off\nStupid Mode = on\n\n# Your modem device\nModem = /dev/ttyS0\n\n# Set Baud rate\nBaud = 115200\n\nInit = ATZ\n\n#Set band to LTE-M\nInit1 = AT+CBANDCFG=\"NB-IOT\",20\n\n# Set APN\nInit2 = AT+CGDCONT=1,\"IP\",\"scs.telekom.tma.iot\"\nInit3 = AT+CNCFG=0,1,\"scs.telekom.tma.iot\"\n\n#LTE-M with Telekom Deutschland\nInit4= AT+COPS=0,2,\"26201\",8\n\n#dial with *99# \nPhone = *99#\n\n# These often suffice, but your ISP might require different details. They'r\n# often dummy details used for all users on the ISP, frequently the ISP's\n# name, but some ISP's do require you to use a real username and password.\nUsername = dummy\nPassword = dummy",
      "language": "text",
      "name": "wvdial.conf"
    }
  ]
}
[/block]

After you have saved your file you are able to get your connection. Dial with the following command:

[block:code]
{
  "codes": [
    {
      "code": "wvdial sim7070g",
      "language": "shell",
      "name": "dial"
    }
  ]
}
[/block]

If dialing was successful you can add your route:

[block:code]
{
  "codes": [
    {
      "code": "sudo ip route add 172.27.128.0/22 dev ppp0",
      "language": "shell",
      "name": "add route"
    }
  ]
}
[/block]

[block:callout]
{
  "type": "info",
  "title": "Congratulation!",
  "body": "If everything has worked so far, you are now able to access our network with your RPi SIMCom setup via a PPP connection."
}
[/block]

###

###

## 3 Register and subscribe your device

Before you can start working with the IoTerop LwM2M client you need to register your device to our IoT Creators Portal. Furthermore it is helpful to register an endpoint URL and do a lifecycle subscription on your device.

###

\###3.1 Register your device
Usually you would use your device IMEI but in our case the IoTerop client is the "device". So let's name it **IoTeropCustomClient\_1**. The **\_1** is not necessary but the easiest way when it comes to changing the code later.\
To add your device to the IoT Creators Portal, use the following Northbound API:

[block:parameters]
{
  "data": {
    "0-0": "URL",
    "0-1": "https://api.scs.iot.telekom.com:443/m2m/endpoints",
    "1-0": "Method",
    "1-1": "POST",
    "2-0": "Header",
    "2-1": "Content-Type: application/json,\nAccept: application/json,\nAuthorization: Basic **<<<YOUR BASE64 STRING>>>**",
    "3-0": "Body",
    "3-1": "{\n\"serialNumber\": \"IoTeropCustomClient_1\",\n\"groupName\": \"**<<<YOUR GROUP NAME>>>**\",\n\"protocol\": \"LWM2M\",\n\"additionalParams\": {},\n\"address\": \"\",\n\"identifier\": \"IoTeropCustomClient_1\"\n}",
    "h-0": "Components",
    "h-1": "Content"
  },
  "cols": 2,
  "rows": 4
}
[/block]

You can find the required information (Group name & login credentials) in your IoT Creators account.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/dca3b76-2021-08-31_14_09_05-Projects___IoT_Creators.png",
        "2021-08-31 14_09_05-Projects _ IoT Creators.png",
        1898,
        716,
        "#f8f5f7"
      ]
    }
  ]
}
[/block]

For the authentication you need to encode your credentials to base64 format. Therefore you can use [this website](https://www.base64encode.org/). Just enter USERNAME:PASSWORD and copy your generated string. Replace **<<<YOUR BASE64 STRING>>>** with the generated string from the website.

###

### 3.2 Register an Application URL

###

I recommend to do a lifecycle subscription on your device so you can see if everything works fine. The easiest way to do that is [beeceptor](https://beeceptor.com/). Just enter an endpoint name (e.g. ioterop-custom-client.free.beeceptor.com) and copy the generated endpoint.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/060ae6e-2022-02-08_15_05_47-Beeceptor_-_Zero_Coding_Rest_API_Mocking_-_Rest_API_Mock_Server.png",
        "2022-02-08 15_05_47-Beeceptor - Zero Coding Rest API Mocking - Rest API Mock Server.png",
        1455,
        1175,
        "#e9ebed"
      ]
    }
  ]
}
[/block]

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/8ef5a25-2022-02-08_15_06_22-ioterop-custom-client_-_Rest_API_Mock_Server.png",
        "2022-02-08 15_06_22-#ioterop-custom-client - Rest API Mock Server.png",
        1452,
        689,
        "#e2e4e6"
      ]
    }
  ]
}
[/block]

###

Use this URL to replace the **<<<YOUR APPLICATION URL>>>** in the following API. You also need the string from your credentials, which you have already used in the registration API before.

[block:parameters]
{
  "data": {
    "0-0": "URL",
    "1-0": "Method",
    "1-1": "PUT",
    "3-1": "{\n\"headers\" :{\"authorization\" : \"**<<<YOUR BASE64 STRING>>>**\"},\n\"url\" : \"**<<<YOUR APPLICATION URL>>>**\"\n}",
    "3-0": "Body",
    "2-0": "Header",
    "2-1": "Accept : application/json\nContent-Type : application/json",
    "0-1": "https://api.scs.iot.telekom.com:443/m2m/applications/registration",
    "h-0": "Components",
    "h-1": "Content"
  },
  "cols": 2,
  "rows": 4
}
[/block]

###

### 3.3 Lifecycle Subscription

I also recommend to do a lifecycle subscription so you can see all your device activities. To do that, you can use the following API with your group name:

[block:parameters]
{
  "data": {
    "0-1": "https://api.scs.iot.telekom.com/m2m/subscriptions?type=lifecycleEvents",
    "0-0": "URL",
    "1-0": "Method",
    "2-0": "Header",
    "3-0": "Body",
    "1-1": "POST",
    "3-1": "{\n    \"criteria\":{\"serialNumbers\":[\"IoTeropCustomClient_1\"]},\n   \"deletionPolicy\": 0,\n    \"groupName\": \"**<<<YOUR GROUPNAME>>>**\",\n   \"events\": [\"registration\", \"deregistration\", \"update\", \"expiration\"],\n    \"subscriptionType\": \"lifecycleEvents\"\n}",
    "2-1": "Accept : application/json\nContent-Type : application/json",
    "h-0": "Components",
    "h-1": "Content"
  },
  "cols": 2,
  "rows": 4
}
[/block]

###

\###3.4 Resource Subscription
Subscribe to the resource of our measured CPU temperature.

[block:parameters]
{
  "data": {
    "0-0": "URL",
    "1-0": "Method",
    "2-0": "Header",
    "3-0": "Body",
    "3-1": "{\n   \"criteria\": {\"serialNumbers\": [\"IoTeropCustomClient_1\"]},\n    \"deletionPolicy\": 0,\n    \"groupName\": \"**<<<YOUR GROUPNAME>>>**\",\n    \"resources\": [ {\"resourcePath\":\"3303/0/5700\"}, {\"resourcePath\":\"3/0/0\"}],\n    \"subscriptionType\": \"resources\"\n}",
    "0-1": "https://api.scs.iot.telekom.com/m2m/subscriptions?type=resources",
    "1-1": "POST",
    "2-1": "Accept : application/json\nContent-Type : application/json",
    "h-0": "Components",
    "h-1": "Content"
  },
  "cols": 2,
  "rows": 4
}
[/block]

###

\##4 Edit the IoTerop IOWA Custom Object Dynamic Client
Let us start with downloading the public version of IoTerop's IOWA LwM2M stack from [GitHub](https://github.com/IOTEROP/IOWA).
Now you can do the changes as in the following screenshots (detailed description below the images).

Before we will start editing the main file we will need to do two little changes in the header file.
As mentioned we will use the custom object dynamic client, so please go to the **samples/04-custom\_object\_dynamic** folder and open the **sample\_object.h** file.

###

\###4.1 sample\_object.h

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/a242728-rpi1.png",
        "rpi1.png",
        1459,
        814,
        "#212322"
      ],
      "caption": "sample_object.h"
    }
  ]
}
[/block]

* 1: Change **SAMPLE\_OBJECT\_ID** from 3200 to **3303**

* 2: Lower the **SAMPLE\_RES\_COUNT** from 3 to **1**

* 3: Definition:

[block:code]
{
  "codes": [
    {
      "code": "//Delete:\n#define SAMPLE_OBJECT_BOOLEAN_RES_ID 5500\n#define SAMPLE_OBJECT_STRING_RES_ID 5750\n#define SAMPLE_OBJECT_INTEGER_RES_ID 5503\n\n//Add:\n#define SAMPLE_OBJECT_FLOAT_RES_ID 5700",
      "language": "c",
      "name": "Replace"
    }
  ]
}
[/block]

* 4: Replace the content of  "SAMPLE\_RES\_DESCRIPTION{...}
  with the following line:

[block:code]
{
  "codes": [
    {
      "code": "\\ {SAMPLE_OBJECT_FLOAT_RES_ID,   IOWA_LWM2M_TYPE_FLOAT,   IOWA_OPERATION_READ | IOWA_OPERATION_WRITE, IOWA_RESOURCE_FLAG_NONE} \\ ",
      "language": "c",
      "name": "Set R/W rights"
    }
  ]
}
[/block]

* 5: Replace the content of "typedef struct{...}sample\_obkect\_values\_t"
  with  the following line:

[block:code]
{
  "codes": [
    {
      "code": "float floatValue;",
      "language": "c",
      "name": "define contained values"
    }
  ]
}
[/block]

###

\###4.2 sample\_object.c
Afterwards we have to adjust the **sample\_object.c** file.
Open it and replace the cases of the switch case with the following case.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/471ccf8-rpi2.png",
        "rpi2.png",
        840,
        660,
        "#222424"
      ],
      "caption": "sample_object.c"
    }
  ]
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "case 5700:\n  if (operation == IOWA_DM_READ)\n  {\n    dataP[i].value.asFloat = objectValuesP->floatValue;\n  }\n  else if (operation == IOWA_DM_WRITE)\n  {\n    objectValuesP->floatValue = dataP[i].value.asFloat;\n  }\n  break;",
      "language": "c",
      "name": "case 5700 for float value"
    }
  ]
}
[/block]

###

\###4.3 main.c
Now we can finally edit the **main.c** file without getting errors. Just open it and do the following changes:

**Modification 1-2**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/7e7b6ea-rpi3.png",
        "rpi3.png",
        1206,
        569,
        "#222322"
      ],
      "caption": "main.c modification 1 & 2"
    }
  ]
}
[/block]

* 1: Replace the IP address from IoTerop's test server with the one from IoT Creators
  IoT Creators LwM2M Server: **172.27.130.11**

* 2: Set the ID for the endpoint name to **1** instead of generating it from your computer.
  This is the part that I mentioned at the beginning. It is responsible for the **\_1** of our device name. The rest (**IoTeropCustomClient**) will be defined in the build progress.

###

**Modification 3**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/450d774-rpi4.png",
        "rpi4.png",
        901,
        664,
        "#232423"
      ],
      "caption": "main.c modification 3"
    }
  ]
}
[/block]

* 3: Add the following function to read the CPU temperature:

[block:code]
{
  "codes": [
    {
      "code": "float read_cpu_temperature()\n{\nFILE *temperatureFile;\nfloat T;\ntemperatureFile = fopen (\"/sys/class/thermal/thermal_zone0/temp\", \"r\");\nif (temperatureFile == NULL)\n{\n    printf(\"Cannot read CPU Temperatur!\")\n}\nfscanf (temperatureFile, \"%f\", &T);\nT /= 1000; //to transfer in degrees\nprintf (\"CPU temperature = %6.3f C.\\n\", T);\nfclose (temperatureFile);\nreturn T;\n}",
      "language": "c",
      "name": "read_cpu_temperatur()"
    }
  ]
}
[/block]

###

**Modification 4-6**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/a99458d-rpi5.png",
        "rpi5.png",
        1573,
        891,
        "#232423"
      ],
      "caption": "main.c modification 4-6"
    }
  ]
}
[/block]

* 4: Set value

[block:code]
{
  "codes": [
    {
      "code": "// Delete:\nobjectValues.booleanValue = true;\nobjectValues.integerValue = 10;\nobjectValues.stringValue = 0;\n\n//Add:\nobjectValues.booleanValue = read_cpu_temperature();",
      "language": "c",
      "name": "Replace"
    }
  ]
}
[/block]

* 5: Replace loop content 1

[block:code]
{
  "codes": [
    {
      "code": "//Delete: \nobjectValues.booleanValue = !objectValues.booleanValue;\nobjectValues.integerValue = objectValues.integerValue + 1;\n\n//Add:\nobjectValues.floatValue = read_cpu_temperature();",
      "language": "c",
      "name": "Replace loop 1/2"
    }
  ]
}
[/block]

* 6: Replace loop content 2

[block:code]
{
  "codes": [
    {
      "code": "//Delete:\niowa_client_object_resource_changed(iowaH, SAMPLE_OBJECT_ID, 0, SAMPLE_OBJECT_BOOLEAN_RES_ID);\niowa_client_object_resource_changed(iowaH, SAMPLE_OBJECT_ID, 0, SAMPLE_OBJECT_INTEGER_RES_ID);\n\n//Add:\niowa_client_object_resource_changed(iowaH, SAMPLE_OBJECT_ID, 0, SAMPLE_OBJECT_FLOAT_RES_ID);",
      "language": "c",
      "name": "Replace loop 2/2"
    }
  ]
}
[/block]

Save the files and that's it. Now you are ready to build your custom client.

###

###

\##5 Build and run the client
We will build our custom object dynamic just like in the documentation from IoTerop:

Create the **build** folder in the IOWA repository:

[block:code]
{
  "codes": [
    {
      "code": "~/IOWA$ mkdir build",
      "language": "shell",
      "name": "Create build folder"
    }
  ]
}
[/block]

Go to your new folder:

[block:code]
{
  "codes": [
    {
      "code": "~/IOWA$ cd build",
      "language": "shell",
      "name": "go to build"
    }
  ]
}
[/block]

Launch cmake in debug mode and define the endpoint name. This is the part where we define the rest of our device name -> **IoTeropCustomClient**

[block:code]
{
  "codes": [
    {
      "code": "~/IOWA/build$ cmake -DCMAKE_BUILD_TYPE=Debug -DIOWA_DEV_NAME=\"IoTeropCustomClient\"",
      "language": "shell",
      "name": "cmake"
    }
  ]
}
[/block]

Build the client and the server:

[block:code]
{
  "codes": [
    {
      "code": "~/IOWA/build$ make -j 4",
      "language": "shell",
      "name": "build"
    }
  ]
}
[/block]

After the build progress is completed we can go to the **04-custom\_object\_dynamic** folder:

[block:code]
{
  "codes": [
    {
      "code": "~/IOWA/build$ cd samples/04-custom_object_dynamic ",
      "language": "shell",
      "name": "change directory"
    }
  ]
}
[/block]

Now we can run the client:

[block:code]
{
  "codes": [
    {
      "code": "~/IOWA/build/samples/04-custom_object_dynamic$ ./custom_object_dynamic_client",
      "language": "shell",
      "name": "run the client"
    }
  ]
}
[/block]

###

###

\##6 Read Request
While the custom client is running you can use the following API with your string of your credentials to do a read request on the temperature ressource  (3303/0/7500).

[block:parameters]
{
  "data": {
    "0-0": "URL",
    "0-1": "https://api.scs.iot.telekom.com:443/m2m/endpoints/IoTeropCustomClient_1/3303/0/7500",
    "1-0": "Method",
    "1-1": "GET",
    "2-0": "Header",
    "2-1": "Content-Type : application/json\nAuthorization : Basic **<<<YOUR BASE64 STRING>>>**",
    "h-0": "Components",
    "h-1": "Content"
  },
  "cols": 2,
  "rows": 3
}
[/block]

[block:callout]
{
  "type": "info",
  "body": "After executing you should be able to see the event in your Beeceptor.",
  "title": "Check your Beeceptor!"
}
[/block]