... | ... | @@ -138,8 +138,122 @@ To get rid of the wrong eclipse warning, press F5 and also ALT + F5 to update pr |
|
|
|
|
|
#### Add the listener code
|
|
|
|
|
|
Add a new Java File: `EnoceanRequestHandler.java` with the content
|
|
|
|
|
|
```java
|
|
|
package org.enosar.application.tutorialenoceanswitch;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.enosar.core.communication.api.CommunicationService;
|
|
|
import org.enosar.core.messaging.api.MessageConsumer;
|
|
|
import org.enosar.core.messaging.dto.EventDTO;
|
|
|
import org.osgi.service.log.LogService;
|
|
|
|
|
|
public class EnoceanRequestHandler
|
|
|
implements MessageConsumer{
|
|
|
|
|
|
private static final String STORE_PREFIX = "org.enosar.application.smartthings";
|
|
|
private Map<String, CommunicationService> serviceArray;
|
|
|
|
|
|
@Override
|
|
|
public synchronized void push(EventDTO event, String topic) {
|
|
|
Activator.getLog().log(LogService.LOG_INFO, "pushed topic: `" + topic + "` EventDTO: from:`"
|
|
|
+ event.getFrom() + "`,to:`" + event.getTo() + "`,body:`" + event.getBody() + "`");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The EnoceanRequestHandler implements the MessageConsumer interface. It implements the push method, which is called by the ENOSAR Messaging framework when an EnOcean message comes in. Within the push we log what happend.
|
|
|
|
|
|
Now wire everything together in your `Activator.java`. Edit the start method:
|
|
|
|
|
|
```java
|
|
|
public void start(BundleContext bundleContext) throws Exception {
|
|
|
context = bundleContext;
|
|
|
logServiceTracker = new LogServiceTracker(context);
|
|
|
logServiceTracker.open();
|
|
|
|
|
|
// register request handler to listen to communication services for EnOcean
|
|
|
Dictionary<String, Object> propertiesEnOcean = new Hashtable<>();
|
|
|
//listen to all in.homeautomation.enocean.* topics
|
|
|
propertiesEnOcean.put(Constants.MSG_TOPIC, new String[] {"in.homeautomation.enocean.*"});
|
|
|
//register the new service
|
|
|
context.registerService(
|
|
|
new String[] {MessageConsumer.class.getName()},
|
|
|
new EnoceanRequestHandler(), propertiesEnOcean);
|
|
|
|
|
|
Activator.getLog().log(LogService.LOG_INFO, "org.enosar.application.tutorialenoceanswitch started.");
|
|
|
}
|
|
|
```
|
|
|
It defineds, that our EnoceanRequestHandler listens to all in.homeautomation.enocean. topics and registers that service.
|
|
|
|
|
|
|
|
|
The full tutorial code can be found here: TODO-NE
|
|
|
|
|
|
Next step ist to build our bundle and upload it to our ENOSARPI. Richt click the pom.xml Run as -> Maven build. If everything works you should see
|
|
|

|
|
|
|
|
|
Go into the `target/` directory where you find your new bundle
|
|
|

|
|
|
|
|
|
Upload this bundle to the Pi `~/ENOSAR/felix-framework-5.4.0/load/` folder. For ssh Filetransfer i use FileZille
|
|
|

|
|
|
|
|
|
Login to the pi and start ENOSAR
|
|
|
```shell
|
|
|
pi@enosarpi:~/ENOSAR/felix-framework-5.4.0 $ java -jar bin/felix.jar
|
|
|
____________________________
|
|
|
Welcome to Apache Felix Gogo
|
|
|
|
|
|
g! 2017-02-28 13:17:31.066:INFO::FelixStartLevel: Logging initialized @3899ms
|
|
|
2017-02-28 13:17:31.316:INFO:oejs.Server:FelixStartLevel: jetty-9.2.14.v20151106
|
|
|
2017-02-28 13:17:31.665:INFO:oejsh.ContextHandler:FelixStartLevel: Started o.e.j.s.ServletContextHandler@1068806{/,null,AVAILABLE}
|
|
|
2017-02-28 13:17:31.668:INFO:oejs.Server:FelixStartLevel: Started @4502ms
|
|
|
2017-02-28 13:17:31.793:INFO:oejs.ServerConnector:FelixStartLevel: Started ServerConnector@1353e01{HTTP/1.1}{0.0.0.0:8080}
|
|
|
[INFO] Started Jetty 9.2.14.v20151106 at port(s) HTTP:8080 on context path / [minThreads=8,maxThreads=200,acceptors=1,selectors=2]
|
|
|
DEBUG:org.enosar.core.communication 29> new addresserviceaware object
|
|
|
INFO:org.enosar.core.auth 21> granting communication access for bundle org.enosar.application.smartthings to service org.enosar.service.io.rabbitmq
|
|
|
INFO:org.enosar.core.auth 21> granting communication access for bundle org.enosar.application.smartthings to service org.enosar.service.io.rabbitmq
|
|
|
INFO:org.enosar.application.smartthings 22> serviceArray registered
|
|
|
INFO:org.enosar.core.auth 21> granting communication access for bundle org.enosar.mgmt.modules to service org.enosar.service.io.http
|
|
|
INFO:org.enosar.core.messaging 28> adding subscriber - now containing 7
|
|
|
INFO:org.enosar.core.webserver 33> HTTPServiceTracker started
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/message Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/module Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/update Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register static resource /enosar/ui - bundle18 Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/access Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/config Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/user Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/permission Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via /enosar/address Auth: true
|
|
|
INFO:org.enosar.core.webserver 33> register servlet via / Auth: false
|
|
|
2017-02-28T13:17:33.361 [INFO--org.enosar.service.io.enocean.basedriver.impl.EnOceanBaseDriverENOSAR] initial host path : /dev/ttyAMA0
|
|
|
DEBUG:org.enosar.core.communication 29> new addresserviceaware object
|
|
|
2017-02-28T13:17:33.507 [ERROR-org.enosar.service.io.enocean.impl.DeviceHandler] Error AddressService is null
|
|
|
INFO:org.enosar.core.auth 21> granting communication access for bundle org.enosar.application.smartthings to service org.enosar.service.io.rabbitmq
|
|
|
INFO:org.enosar.core.auth 21> granting communication access for bundle org.enosar.application.smartthings to service org.enosar.service.io.rabbitmq
|
|
|
INFO:org.enosar.application.smartthings 22> serviceArray registered
|
|
|
INFO:org.enosar.core.auth 21> granting communication access for bundle org.enosar.mgmt.modules to service org.enosar.service.io.http
|
|
|
INFO:org.enosar.core.messaging 28> adding subscriber - now containing 8
|
|
|
INFO:org.enosar.service.datastore.jsonfile 20> mapping service injected
|
|
|
INFO:org.enosar.application.smartthings 22> DataStoreService injected
|
|
|
DEBUG:org.enosar.core.datastore 24> injecting org.enosar.service.datastore.jsonfile with type persistent
|
|
|
INFO:org.enosar.core.communication 29> injected DSS JSONFileDataStoreServiceImpl
|
|
|
INFO:org.enosar.service.io.rabbitmq 25> trying to (re)connect to RabbitMQ server...
|
|
|
INFO:org.enosar.application.smartthings 22> MappingService injected
|
|
|
INFO:org.enosar.core.auth 21> could not grant messaging access for bundle org.enosar.application.tutorialenoceanswitch to topic in.homeautomation.enocean.*, bundle undefined
|
|
|
INFO:org.enosar.core.messaging 28> adding subscriber - now containing 8
|
|
|
INFO:org.enosar.application.tutorialenoceanswitch 36> org.enosar.application.tutorialenoceanswitch started.
|
|
|
INFO:org.enosar.service.io.rabbitmq 25> ... RabbitMQ connected
|
|
|
```
|
|
|
|
|
|
Currently our tutorialenoceanswith is not allowed to access the messaging framework `INFO:org.enosar.core.auth 21> could not grant messaging access for bundle org.enosar.application.tutorialenoceanswitch to topic in.homeautomation.enocean.*, bundle undefined` so we have to grant the access to it. In the Webinterface goto Access Violations and click on grant for our new bundle
|
|
|
|
|
|

|
|
|
|
|
|
Click on Update so that the permissions are granted.
|
|
|
 |