Skip to main content

IoT gateway with Raspberry Pi using Eclipse Kura

The gateway uses a Raspberry Pi with Eclipse Kura to run the application that controls the relay board, Eclipse Leshan to communicate with the sensor, and Eclipse Paho to communicate with the server. The sources of the project are available on GitHub:

Eclipse Kura

Eclipse Kura offers a platform that can live at the boundary between the private device network and the local network, public Internet or cellular network providing a manageable and intelligent gateway for that boundary capable of running applications that can harvest locally gathered information and deliver it reliably to the cloud.
Eclipse Kura can be installed on a Raspberry Pi but it requires Raspbian, gdebi and OpenJDK. You can find the detailed instrucions on official web site:
The Kura development environment may be installed on a Windows, Linux, or Mac OS. The setup instructions will be the same across OSs though each system may have unique characteristics. Eclipse Kura Development Environment consists of the following components: JVM (Java JDK SE 8 or Open JDK 8), Eclipse IDE, Kura Workspace. You can find the detailed instrucions on official web site:
The GPIOService may be used to access the gpio pins that control the relay board but to get a reference to GPIOService you need to setup a service traker.

String selectedGPIOServicePid = DEFAULT_GPIO_SERVICE_PID;
String filterString = String.format("(&(%s=%s)(",
  Constants.OBJECTCLASS, GPIOService.class.getName(), selectedGPIOServicePid);
Filter filter = null;
try {
 filter = this.bundleContext.createFilter(filterString);
} catch (InvalidSyntaxException e) {
 s_logger.error("Filter setup exception ", e);

this.gpioServiceTrackerCustomizer = new GPIOServiceTrackerCustomizer();
this.gpioServiceTracker = new ServiceTracker<>(this.bundleContext, filter,

Eclipse Leshan

Eclipse Leshan is an OMA Lightweight M2M (LWM2M) implementation in Java. Leshan relies on the Eclipse Californium project for the CoAP and DTLS implementation and provides libraries which help people to develop their own Lightweight M2M server and client.
The project also provides a client, a server and a bootstrap server demonstration as an example of the Leshan API and for testing purpose.
To init the LWM2M server you have to set the local address, to load the models and register a listener.

// Prepare LWM2M server
LeshanServerBuilder builder = new LeshanServerBuilder();
builder.setLocalAddress(null, coap_port);
builder.setLocalSecureAddress(null, coaps_port);
builder.setEncoder(new DefaultLwM2mNodeEncoder());
LwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();

// Create CoAP Config
NetworkConfig coapConfig;
File configFile = new File(NetworkConfig.DEFAULT_FILE_NAME);
if (configFile.isFile()) {
 coapConfig = new NetworkConfig();
} else {
 coapConfig = LeshanServerBuilder.createDefaultNetworkConfig();;

// Define model provider
List<ObjectModel> models = ObjectLoader.loadDefault();
models.addAll(ObjectLoader.loadDdfResources("/models/", modelPaths));
LwM2mModelProvider modelProvider = new StaticModelProvider(models);

// Create and start LWM2M server
lwServer =;"Bundle " + APP_ID + " LeshanServer build!");

sensorRegistrationListener = new SensorRegistrationListener();

try {"Bundle " + APP_ID + " LeshanServer start!");
} catch (Exception e) {

Eclipse Paho

Eclipse Paho is a set of scalable open-source implementations of open and standard messaging protocols aimed at new, existing, and emerging applications for Machine-to-Machine (M2M) and Internet of Things (IoT). To init the MQTT client you need to set the broker, the username and the password.

MemoryPersistence persistence = new MemoryPersistence();
mqttClient = new MqttClient(mqttBroker, APP_ID, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setPassword(mqttPassword.toCharArray());"MqttClient.Connecting to broker: " + mqttBroker);


Popular posts from this blog

IoT temperature sensor with ESP8266 using LWM2M (Eclipse Wakaama)

The sensor uses an ESP8266 board with the protocol Lightweight M2M to communicate the temperature read by DS18B20 to the gateway. The sources of the project are available on GitHub: ESP8266 The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability produced by Espressif Systems. The avalability of same SDK allows the chip to be programmed, removing the need for a separate microcontroller. To program the microchip i use the SDK Arduino core for ESP8266 WiFi chip  and  PlatformIO , that is an open source ecosystem for IoT development. LwM2M Lightweight M2M is a protocol from the Open Mobile Alliance for M2M or IoT device management and communication. It uses CoAP, a light and compact protocol with an efficient resource data model, for the application layer communication between LWM2M Servers and LWM2M Clients. Each service on a constrained device/sensor/actor is

Smart solar water heating solution to take part in the Open IoT Challenge 4.0!

Smart solar water heating solution uses IoT and AI technologies to improve the efficiency of passive solar water heating system. This solution is designed to take part in the Open IoT Challenge 4.0! Solar water heating Solar water heating (SWH) is the conversion of sunlight into heat for water heating using a solar thermal collector. Solar water heating systems include storage tanks and solar collectors. There are two types of solar water heating systems: active, which have circulating pumps and controls, and passive, which don't. Passive solar water heating systems are typically less expensive than active systems, but they're usually not as efficient. However, passive systems can be more reliable and may last longer. The solar panels heat the water in the storage tank when they are affected by the sun rays. The water reaches the highest temperature when the sun is stronger. If the water in the solar panel is hot the divert valve close the flow towards the boiler s

Connect wan automatically at boot and after a disconnection on OpenWrt

OpenWrt is an open source project for embedded operating system based on Linux, primarily used on embedded devices to route network traffic. I install OpenWrt on my Netgear DGN3500, an ADSL2+ gateway with wireless acccess point integrated. Finally the wifi signal is strong but the internet connection does not go up at boot or after a disconnection. Found solutions I find the following solutions: to schedule the reboot and the reconnections by cron ( ), to write a script to reconnect after a disconnection ( ) or to insert the command "ifup wan" in the file "/etc/init.d/network". Recomended solution To take all the advantages of the previous solutions i write the script "wanup" to connect the wan and i call its at boot and after the disconnection. To call the script "wanup" at boot yo