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: https://github.com/brusdev/smart-solar-heating-system/tree/master/gateway


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: https://eclipse.github.io/kura/intro/raspberry-pi-quick-start.html
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: https://eclipse.github.io/kura/dev/kura-setup.html
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)(kura.service.pid=%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,
  this.gpioServiceTrackerCustomizer);
this.gpioServiceTracker.open();

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();
builder.setDecoder(decoder);

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

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

// Create and start LWM2M server
lwServer = builder.build();
s_logger.info("Bundle " + APP_ID + " LeshanServer build!");

sensorRegistrationListener = new SensorRegistrationListener();
lwServer.getRegistrationService().addListener(sensorRegistrationListener);

try {
 s_logger.info("Bundle " + APP_ID + " LeshanServer start!");
 lwServer.start();
} catch (Exception e) {
 s_logger.error(e.toString());
 e.printStackTrace();
 lwServer.stop();
}

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.setCleanSession(true);
connOpts.setUserName(mqttUsername);
connOpts.setPassword(mqttPassword.toCharArray());
s_logger.info("MqttClient.Connecting to broker: " + mqttBroker);
mqttClient.connect(connOpts);
s_logger.info("MqttClient.Connected");

Comments

Popular posts from this blog

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 so the boile…

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: https://github.com/brusdev/smart-solar-heating-system/tree/master/sensor

ESP8266The 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 modelled as an LWM2M o…

Smart solar water heating solution final report for 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 has been developed 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 so the …