The following tools are required for this tutorial
- JAVA 1.8 (To run the oneM2M platform)
- Node JS (To run the oneM2M device simulator and oneM2M applications)
Download the oneM2M demo project from Github from the following link:
https://github.com/mbenalaya/onem2m-demo
The project contains the following folders:
- onem2m-platform
- onem2m-device-simulator
- onem2m-app
Open a command line interface and change directory to "onem2m-platform”
4.1. Configure the oneM2M platform (Optional)
Before you start the oneM2M platform, if needed, you can change the configuration of the platform by editing the file “configuration/config.ini” using a text editor like notepad.
The default configuration works for a local demonstration. The platform will listen on ports 8080 and 8443. The database is reset after each restart.
4.2. Start the oneM2M platform
Start the platform by executing the "start.bat" script on Windows or "start.sh" on Linux and Mac OS.
4.3. Login to oneM2M web interface
Open the following URL in your browser to access the oneM2M platform web interface: http://127.0.0.1:8080/webpage
Enter "Cae-admin" as originator then click on “connect”.
Open a new command line interface and change directory to "onem2m-device-simulator".
5.1. Install required node modules
Install the required node modules using the following command:
> npm install
5.2. Configure the simulator (Optional)
You can keep the default configuration for a local demonstration.
If needed, you can change the configuration by editing the config file “default.json” file located in the "config" folder using a text editor.
Before starting the oneM2M simulator, if needed, you can update the target oneM2M platform by editing the "cse" section:
{
"cse":{
"ip":"127.0.0.1",
"port": 8080,
"id":"server",
"name":"server"
},
...
}
You can use the same template to add your own sensors and actuators in the "templates" section (Set the "stream" attribute to "up" for sensors and "down" for actuators). Any new template added to the list will be incorporated by the simulator.
"templates":[
{
"stream":"up",
"type": "luminosity",
"unit": "Lux",
"min":200,
"max":400,
"freq":10,
"icon": "https://link/to/luminosity/icon.png"
},
{
"stream":"down",
"type": "lamp",
"unit": "",
"min":0,
"max":1,
"icon": "https://link/to/lamp/icon.png"
},
...
]
}
5.3. Start the simulator
Start the oneM2M device simulator using the following command:
> sudo node app.js
Open the simulator dashboard interface on your browser. By default the simulator is available on the following address: http://127.0.0.1:80
5.3. Simulate virtual oneM2M devices
You can select a type and chose a name for your device then confirm to simulate a device.
Every simulated sensor (e.g. Temperature, Luminosity, Humidity, Power, Presence, etc.) will push data periodically to the oneM2M platform following the configuration file.
It is possible to change the status of every simulated actuator (e.g. Lamp, Buzzer, etc.) using the "update" button. The new status will published immediately to the oneM2M platfom.
You can delete any simulated device by clicking on the "delete" button.
5.4. Simulate a luminosity sensor
Chose the type "Luminosity" and enter "luminosity_0" as name then confirm.
The luminosity sensor pushes data periodically (By default, a random luminosity value between 200 Lux and 400 Lux is published every 10 seconds)
You can visualize the created resources on the platform by refreshing the oneM2M platform interface on the browser (Click on the root element "server" of the resource tree). You should be able to see the "luminosity_0" resource in the tree.
5.4. Simulate a lamp actuator
Chose the type "Lamp" and enter "lamp_0" as name then confirm.
The simulator will create the corresponding actuators on the oneM2M platform. You can visualize the created resources on the platform by refreshing the oneM2M platform interface on your browser (Click on the root element "server" of the resource tree). You should be able to see the "lamp_0" resource in the tree.
The lamp will push an initial random status between 0 and 1, then wait for triggering actions coming from oneM2M applications.
Open a new command line interface and change directory to "onem2m-app"
6.1. Install required node modules
Install the required node modules using the following command:
> npm install
6.2. Configure the monitoring application (Optional)
Open the file "onem2m-monitor-sim.js" with a text editor. You can keep the default configuration if you are running the oneM2M platform and the application in the same machine.
var cseUri = "http://127.0.0.1:8080";
var aeId = "Cae-monitor1"
var aeName = "monitor1";
var aeIp = "127.0.0.1";
var aePort = 4000;
var sensorContainer = "/server/luminosity_0/data";
var actuatorContainer = "/server/lamp_0/data";
6.3. Start the monitoring application
Start the oneM2M monitoring application using the following command:
> node onem2m-monitor-sim.js
You can visualize the created resources on the platform by refreshing the oneM2M platform interface on your browser (Click on the root element "server" of the resource tree). You should be able to see the "monitor1" resource in the tree.
The monitoring application will receive notifications from the luminosity sensors and update the lamp status accordingly according to the following rules:
- If the luminosity is high (value greater than 300 Lux) then the lamp is switch off (Status set to 0).
- If the luminosity is low (value less than 300 Lux) then the lamp is switch on (Status set to 1).
In the simulated lamp console you can see the lamp status switching according to luminosity level.
You can check the lamp status changing according to the luminosity level on the device simulator interface.
Comments