Serial Gateway connection to Openhab
-
@C.r.a.z.y. , maybe the Node-Id Delaration might be ineffektive. The output of OpenHab says your node identifies itself as Node 0 (Node 0 should be the Gateway itself). You should consider to give Static ID´s like:
#define NODE_ID 100
gw.begin(incomingMessage, NODE_ID, true);So far I understand your sketch, yout try to assign a Node-id in the declaration statement
MySensor gw(100);I´m not sure if this works. It will be safe to change it to
MySensor gw();unless you got some very special hardware.
If the Node-Id is assigned properly, your code example should work fine.
@tboha thank you!
I tried motion sensor sketch (without any change) and it works. I also added motion to ui and i can see "motion" -"no motion" notifications.
I will try relay again and give info.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
**How can i add new devices automatically to UI OR add new device button in UI? - No touch to sitemap-items-rules etc files..More deeper : i have a "sensors" frame (like first floor in demo) and all sensors will be added to under this location OR how can i select which device will be added under x frame in UI? **
-
@C.r.a.z.y. OpenHab doesn't offer such methods like "inclusion" or search for unknown devices at the moment. But this is not due to MySensors properties, this is common to all bindings.
Prerequisite for working with OpenHab seems to be the knowledge of your hardware to a very low level (e.g. programming the sensors yourself = MySensors). Accessing the configuration files results in great possibilities but also in much work.There is another User-Interface to this functions - https://github.com/cdjackson/HABmin - you might give this a try to get rid of the Eclipse-part of the OpenHab designer. I haven't tried it, but the slideshows are really impressive. Habmin may result in easier working -- but probably not in less work.
You haven't told us what project you are aiming for - so it's a bit difficult to give a hint what may fit your needs.
Regarding your last question, consider the following example:
String HomeMaticS1 "Status1-1 [%s]" <shield> (HomeMatic,kitchen, FirstFloor) {homematic="address=JEQ0459986, channel=1, parameter=LED_STATUS" }It is a String definition for my Homematic controlling one of 16 dual-color LEDs
String denotes the type of this object
HomematicS1 ist the name of this object.
"Status1-1" ist the label displayed in the browser.,** [%s]** is a formating directive.
**<shield> **is the name of the icon (which has to reside in \OpenHab1.6.1\webapps\images\shield.png --with exact this name)
The round parenthesis **(Homematic, kitchen, FirstFloor) **tells Openhab to which group this object belongs --yes, one object may belong to many groups (= frames).The rest of this declaration implements the homematic binding with parameters you should know before - as mentioned above.
The other 15 LEDControls are simply constructed by copy&paste and changing the numbers accordingly. Inconsistent numbering is a nice pitfall here and provides you with many happy hours.
With the following Frame in the current .sitemap
Frame label="MyFrame" { Group item=HomeMatic icon="homematic" Group item=kitchen icon="kitchen" }Item **HomematicS1 ** will show up in both subframes labeled as "Status1-1".
This applies to switches and other widgets in the same way, so you can operate your actors from within different frames.
-
@C.r.a.z.y. OpenHab doesn't offer such methods like "inclusion" or search for unknown devices at the moment. But this is not due to MySensors properties, this is common to all bindings.
Prerequisite for working with OpenHab seems to be the knowledge of your hardware to a very low level (e.g. programming the sensors yourself = MySensors). Accessing the configuration files results in great possibilities but also in much work.There is another User-Interface to this functions - https://github.com/cdjackson/HABmin - you might give this a try to get rid of the Eclipse-part of the OpenHab designer. I haven't tried it, but the slideshows are really impressive. Habmin may result in easier working -- but probably not in less work.
You haven't told us what project you are aiming for - so it's a bit difficult to give a hint what may fit your needs.
Regarding your last question, consider the following example:
String HomeMaticS1 "Status1-1 [%s]" <shield> (HomeMatic,kitchen, FirstFloor) {homematic="address=JEQ0459986, channel=1, parameter=LED_STATUS" }It is a String definition for my Homematic controlling one of 16 dual-color LEDs
String denotes the type of this object
HomematicS1 ist the name of this object.
"Status1-1" ist the label displayed in the browser.,** [%s]** is a formating directive.
**<shield> **is the name of the icon (which has to reside in \OpenHab1.6.1\webapps\images\shield.png --with exact this name)
The round parenthesis **(Homematic, kitchen, FirstFloor) **tells Openhab to which group this object belongs --yes, one object may belong to many groups (= frames).The rest of this declaration implements the homematic binding with parameters you should know before - as mentioned above.
The other 15 LEDControls are simply constructed by copy&paste and changing the numbers accordingly. Inconsistent numbering is a nice pitfall here and provides you with many happy hours.
With the following Frame in the current .sitemap
Frame label="MyFrame" { Group item=HomeMatic icon="homematic" Group item=kitchen icon="kitchen" }Item **HomematicS1 ** will show up in both subframes labeled as "Status1-1".
This applies to switches and other widgets in the same way, so you can operate your actors from within different frames.
@tboha Thank you for your detailed answer. :+1:
-
@C.r.a.z.y. Maybe the VERA controller is suitable for you. Have a look at http://forum.micasaverde.com/index.php, here especially http://forum.micasaverde.com/index.php/board,27.0.html. VERA has an inclusion mode and obviously supports Raspberry pi with Camera module (I didn't know before). Very probably you need additional additional hardware - I don'know if this is your intention.
-
@CARSTEN I've compiled a modified version of the OpenHab Serial binding with a baud rate of 115200 as this is standard in mysensors.
Download: org.openhab.binding.serial_1.6.0.201411271703.jar
As @tboha suggested you currently have to manage all commands by yourself.
I've attached my modified serial binding here. Please be aware, that all other configurations that depend on serial binding won't work with the modified version, because of the changed baud rate.
I'm currently testing with this Serial Gateway:
Here is my OpenHab configuration for simple testing:
demo.items: demo.items
demo.rules: demo.rules
demo.sitemap: demo.sitemap@TimO said:
@CARSTEN I've compiled a modified version of the OpenHab Serial binding with a baud rate of 115200 as this is standard in mysensors.
Download: org.openhab.binding.serial_1.6.0.201411271703.jar
As @tboha suggested you currently have to manage all commands by yourself.
I've attached my modified serial binding here. Please be aware, that all other configurations that depend on serial binding won't work with the modified version, because of the changed baud rate.
I'm currently testing with this Serial Gateway:
And a litte sensor/relay combination (switch LED on/off and read DHT22):
Here is my OpenHab configuration for simple testing:
demo.items: demo.items
demo.rules: demo.rules
demo.sitemap: demo.sitemapTim did you modify this jar file? Where can i follow updates?
1.6.1.jar version have arduino update problems -
@TimO said:
@CARSTEN I've compiled a modified version of the OpenHab Serial binding with a baud rate of 115200 as this is standard in mysensors.
Download: org.openhab.binding.serial_1.6.0.201411271703.jar
As @tboha suggested you currently have to manage all commands by yourself.
I've attached my modified serial binding here. Please be aware, that all other configurations that depend on serial binding won't work with the modified version, because of the changed baud rate.
I'm currently testing with this Serial Gateway:
And a litte sensor/relay combination (switch LED on/off and read DHT22):
Here is my OpenHab configuration for simple testing:
demo.items: demo.items
demo.rules: demo.rules
demo.sitemap: demo.sitemapTim did you modify this jar file? Where can i follow updates?
1.6.1.jar version have arduino update problems@C.r.a.z.y. said:
Tim did you modify this jar file? Where can i follow updates?
1.6.1.jar version have arduino update problemsYes, I've modified the serial binding to work with mysensors.
I've invested some work to solder a little serial mysensors gateway to test it's stability together with OpenHab. I've soldered two sockets (for an arduino nano and the nrf24l01+) on a perfboard. Currently there are only two sensors with dht22 connected, but everything works stable and smooth.
Next step is to add two battery driven Atmega328p with dht22. I will build them from the scratch.
I'm searching for a solution for the updates of the modified serial binding for OpenHab. My current idea is to commit a change to OpenHab, that allows to set the baudrate as a parameter, so I don't need to maintain updates by myself. Another solution could be a special mysensors binding. That would allow a few additional features, but needs to be maintained.
Little Update:
I've changed the Serial binding from OpenHab and commited a pull request. Let's see what the OpenHab developers think:
-
Problem solved, My pull request has been merged in the 1.7.0 branch.
With the next version OpenHab supports the MySensors serial gateway with the serial binding out of the box.
Baud rate parameter for example in demo.items:
String Arduino "XXXXTemperature" { serial="/dev/ttyACM0@115200" }
-
Thank you for this great information. I have been setting up Openhab for the past month, and I've been trying different types of nodes using Moteino (Arduino clone) and RFM69 radios. I have also started building some scripts for Openhab to help streamline the receipt of serial messages. All of this is due to the great information I have found here and in other places on the forums.
The one issue that has me frustrated is when I reboot OpenHab (I am currently using a headless raspberry pi). In order to get the sensors to work I have to unplug and re-plug in my gateway, and then run around the house and cycle power off and on to all my other nodes. Sometimes this works, and sometimes this doesn't work. Is there a reliable way to restart the serial gateway via software?
I just did some more troubleshooting and noticed that when I fully reboot the entire raspberry pi, that it comes up correctly. However, sometimes I just want to exit and reboot openhab while I'm doing development.
Once I find out how to make this part more reliable, the whole system will be working great! Thank you again for all of your very knowledgeable advice!
-
@Matt-Perry
I don't need to restart the serial gateway when I restart OpenHab.Do you use a static or auto node ids? I'm using static node ids. Maybe that is the reason you have to restart everything?
When restarting OpenHab it outputs something like: "Removing stale Lockfile on "/dev/ttyACM0 .." and that's it.
-
@Matt-Perry
I don't need to restart the serial gateway when I restart OpenHab.Do you use a static or auto node ids? I'm using static node ids. Maybe that is the reason you have to restart everything?
When restarting OpenHab it outputs something like: "Removing stale Lockfile on "/dev/ttyACM0 .." and that's it.
I am giving the nodes static IDs. Here is an example of how I initialize an IR receiver/transmitter that I'm testing...
#include <MySensor.h> #include <SPI.h> #include <IRLib.h> int RECV_PIN = 8; #define CHILD_1 3 // childId #define NODE_ID 101 IRsend irsend; IRrecv irrecv(RECV_PIN); IRdecode decoder; //decode_results results; unsigned int Buffer[RAWBUF]; MySensor gw; MyMessage msg(CHILD_1, V_VAR1); void setup() { irrecv.enableIRIn(); // Start the ir receiver decoder.UseExtnBuf(Buffer); //gw.begin(incomingMessage); gw.begin(incomingMessage, NODE_ID, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("IR Sensor", "1.0"); // Register a sensors to gw. Use binary light for test purposes. gw.present(CHILD_1, S_LIGHT); }Again, if I fully reboot my raspberry pi, it works (I am running Openhab as a startup script). But, if I want to troubleshoot a little bit, and "kill" the Openhab process and then call "start.sh" on the command line, the serial gateway does't reinitialize. Maybe I'm missing a step somewhere?
If this problem only relates to me, I don't want to waste too much forum space. I could very possibly have something set up wrong on my end and I'll figure it out!
Thanks!
-
What did the OpenHab debug messages say?
Did you check the permissions? Which user starts OpenHab with the startup script and which user do you use when you call "start.sh". Maybe there is a block because of the lock file? Kill the lock file (something like: "/var/lock/LCK..ttyUSB0") after killing OpenHab and before restarting with "start.sh".
I'm currently not using a startup script, I'm using "start.sh" within a screen session, which I'm able to resume for debugging or to kill OpenHab.
My network of MySensors nodes keeps working and reporting (temperature for example) and as soon as there is a controller running, the information is received.
-
What did the OpenHab debug messages say?
Did you check the permissions? Which user starts OpenHab with the startup script and which user do you use when you call "start.sh". Maybe there is a block because of the lock file? Kill the lock file (something like: "/var/lock/LCK..ttyUSB0") after killing OpenHab and before restarting with "start.sh".
I'm currently not using a startup script, I'm using "start.sh" within a screen session, which I'm able to resume for debugging or to kill OpenHab.
My network of MySensors nodes keeps working and reporting (temperature for example) and as soon as there is a controller running, the information is received.
Thanks again for the reply. Everything is working now. I believe the issue was with the serial connection moving to ttyUSB1. I'm not sure of why, or how, but I did create a SYMLINK and everything works just fine now, no matter what USB port the device is plugged into.
Thanks again!
-
@TimO I tested your openHAB configuration and it is working fine most of the time. There is still one problem I was not able to fix. Some payloads have a dynamic length. Your example rules base on fixed length of the transmitted values, right?
I tried to split the incoming strings with string.split("\n"), but the \n seems to be removed by openHAB or the serial gateway. Any ide how we can resolve this? Without this issue openHAB would work perfectly together with the serial gateway. -
Hi
I have the same problem with Matt and tried USB01 but didn't work.
When i unplug the usb, server error : Write action failed! Input/output error2015-03-03 19:25:23.682 [ERROR] [b.serial.internal.SerialDevice] - Error writing '100;3;1;0;0;1
' to serial port /dev/ttyUSB0: Input/output error in writeArrayOnly solution for me stop server, unplug serial usb and plug it. I think ---Kill the lock file (something like: "/var/lock/LCK..ttyUSB0")--- will give the same solution like unplug the usb?
-
When i unplug and plug again the serial USB from raspberry :
2015-03-04 20:27:56.413 [INFO ] [runtime.busevents ] - AP4 received command ON
2015-03-04 20:27:56.564 [INFO ] [runtime.busevents ] - Arduino received command 100;1;1;0;0;1Write action failed! Input/output error2015-03-04 20:27:56.610 [ERROR] [b.serial.internal.SerialDevice] - Error writing '100;1;1;0;0;1
' to serial port /dev/ttyUSB0: Input/output error in writeArrayHow can fix this?
-
Why are you using a usb to serial adapter to connect the arduino to the raspberry? The raspberry hat an onboard uart at /dev/ttyAMA0. I am using the internal uart and cannot reproduce this kind of error.
-
Why are you using a usb to serial adapter to connect the arduino to the raspberry? The raspberry has an onboard uart at /dev/ttyAMA0. I am using the internal uart and cannot reproduce this kind of error.
-
Why are you using a usb to serial adapter to connect the arduino to the raspberry? The raspberry has an onboard uart at /dev/ttyAMA0. I am using the internal uart and cannot reproduce this kind of error.
@Jan-Gatzke said:
ttyAMA0
:+1:What version openhab runtime and add ons do you use?
How many nodes do you have and how long time they are working fine without restart rpi?
Please can you upload your config files?1.6.2 or 1.7.0 didn't switch on-off my relays but logs seems ok:
I connected nano pins VIN+GND+TX+RX to RPI 5V+GND+TX+RX , (TX->TX , RX->RX)
osgi> 2015-03-07 15:49:24.409 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.7.0).
2015-03-07 15:49:50.387 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2015-03-07 15:49:51.200 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2015-03-07 15:50:01.540 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'default.items'
2015-03-07 15:50:15.506 [WARN ] [cpr.DefaultAnnotationProcessor] - Unable to detect annotations. Application may fail to deploy.
2015-03-07 15:50:17.567 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'
2015-03-07 15:50:32.786 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
2015-03-07 15:50:38.947 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
2015-03-07 15:50:51.918 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'default.rules'
RXTX Warning: Removing stale lock file. /var/lock/LCK..ttyAMA0
2015-03-07 15:51:01.398 [INFO ] [.service.AbstractActiveService] - NTP Refresh Service has been started2015-03-07 15:51:57.516 [INFO ] [runtime.busevents ] - S2 received command ON
2015-03-07 15:52:08.006 [INFO ] [runtime.busevents ] - S2 received command OFF
2015-03-07 15:52:11.408 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;02015-03-07 15:52:11.722 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1
2015-03-07 15:52:19.544 [INFO ] [runtime.busevents ] - S1 received command ON
2015-03-07 15:52:21.200 [INFO ] [runtime.busevents ] - Arduino received command 51;1;1;0;2;02015-03-07 15:52:22.143 [INFO ] [runtime.busevents ] - S2 received command ON
2015-03-07 15:52:22.259 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;02015-03-07 15:52:23.131 [INFO ] [runtime.busevents ] - AP3 received command ON
2015-03-07 15:52:24.142 [INFO ] [runtime.busevents ] - Arduino received command 100;3;1;0;0;1 -
I've upgraded to the nightly of OpenHab 1.7.0 to see if I'm able to reproduce your problem.
My modified OpenHab 1.6.2 did ran for a few weeks without problems. I'm using an Arduino Nano connected to an old laptop, so no RPi and the FTDI from the Nano. -
@TimO please can you share Openhab files?
+My relay powered from nano icp headers maybe this makes trouble for wifi , i will change this and give update.