Closed amarpulli1994 closed 7 years ago
Hi @amarpulli544 Can you explain to me on a high level what you want to do here. I'm not sure I get it.
Do you want to send ASCII commands to the serial port ? The current setup only support setting DIO port to Low or high, nothing more.
If you want to send ASCII command to a XBee device , it is a bit more tricky as it will be very specific to the device you are using. I would need to know more about what is your plan. Regards. Stephan
Hi @g1velo ,
I need to send ASCII's or strings through serial ports(DIN,DOUT) of XBEE, either using AT mode or API modes. So that when i send data(ASCII) from COORDINATOR(XBEE) to END DEVICE(XBEE), it should receive through the Serial ports DIN and DOUT of END DEVICE.
Thanks, Amar.
I believe it should be DIN rather DOUT.
Ok so make things clear : @amarpulli544 & @kirantpatil .
You have a controller attached behind a Xbee End device.
To make this work we need to know which ASCII command should be sent from the OH2/coordinator to the controller attached. We do also need to know what are the commands sent by your controller and how to parse this commands and how to mach it against the thing registry.
Once we know all this, we can write the code that will allow this to work.
Hello @g1velo ,
I want to turn ON particular Switch. Here in my case number of Switches. My Switches configured like this
Switch Living_S1 "living_light1" { channel = "snavxbee2:sample:gateway:0013A20041268525:S1" }
Switch Living_S2 "living_light2" { channel = "snavxbee2:sample:gateway:0013A20041268525:S2" }
Switch Living_S3 "living_light3" { channel = "snavxbee2:sample:gateway:0013A20041268525:S3" }
So i need to send ASCII Commands to End Device like this S1=ON
, S1=OFF
, S2=ON
, S2=OFF
,
S3=ON
, S3=OFF
Thanks, Amar.
Is that the full list of switches you would like to activate/deactivate ?
To start with we would like to go with Switch item, if that works then we can keep adding new item types (dimmer, color and so on).
I made the modifications. the thing should be set as : Living_S1 "living_light1" { channel = "snavxbee2:cafe1000:gateway:0013A20041268525:S1" }
If you want to use discovery, you will have to set the DD of the XBee end device to the value : CAFE1000. THis will let the discovery know what to do with the controller. Let me know Regards
Sure Sir thanks. We will try and get back to you.
On Mar 2, 2017 7:54 PM, "g1velo" notifications@github.com wrote:
I made the modifications. the thing should be set as : Living_S1 "living_light1" { channel = "snavxbee2:cafe1000:gateway:0013A20041268525:S1" }
If you want to use discovery, you will have to set the DD of the XBee end device to the value : CAFE1000. THis will let the discovery know what to do with the controller. Let me know Regards
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/g1velo/SNAVXbee2/issues/8#issuecomment-283666485, or mute the thread https://github.com/notifications/unsubscribe-auth/ABH5x4avfso1biJkn74Psi7P0f71k3x1ks5rhtE2gaJpZM4MOdi- .
It is working fine. For receiving part our team will work on it and submit the pull request. Thanks a lot.
Hi @g1velo ,
We would like to work on receiving part of SNAVXbee2 .I need some suggestions to develop receiving part ,then how to proceed with that? Once I will send packet to End Device from Coordinator, its working fine. But End Device receiving two packets at a time.Please let me know the suggestions.
Thanks, Amar.
Hi Amar,
If I understand you well :
You are able to send command from (OH2/COORDINATOR) to the Xbee End Device, nut you see duplicate packets arriving ?
When you are talking about the receiving part ? What does it mean ? From end device to OH2 ?
Yes sir, I need to send packets from End Device to Coordinator/OH2.
ok so you need to have a look at : SNAVXbee2BridgeHandler.dataReceived(XBeeMessage) method.
And you will need to update the section
if (thing.getThingTypeUID().equals(THING_TYPE_CAFE1000)) { }
You will probably need to create a Java class that will parse the received message and decide which channel to update with which value. .
Hello @g1velo ,
Thanks for suggestions . How can I update the method
if (thing.getThingTypeUID().equals(THING_TYPE_CAFE1000)) {
}
Any problem with duplicating packet? Where to create java class in SNAVXbee2 binding?
Thanks, Amar.
Hello @amarpulli544,
Please understand the source code and its flow first.
You end up adding code without understanding it and how it works as a whole.
Thanks.
Also you can see from MANIFEST file, how it uses ESH framework and DIGI Xbee library api.
Hi @amarpulli544 Have a look at what is done in the
if (thing.getThingTypeUID().equals(THING_TYPE_TOSR0XT)) { ... ... }
Section.
thingToUpdate = thing;
Represent the thing with the matching 64 bit address. So the next step are ::
parse the incoming message.
Find which is the channel to update ( from the thingToUpdate using thingToUpdate.getChannels() method )
Update the thing channel using updateState(actionToPerform.getChannelUIDToUpdate(), actionToPerform.getState());
Hope this helps
Hi @g1velo ,
Thanks for your suggestions. So that I need to update DD parameter at Coordinator/OH2?
Thanks, Amar.
You need to update DD to value CAFE1000 on the end Device. This will let the discovery process guess what king of device is attached behind the Xbee End Device.
Discovery process and sending packets are working fine.
But here we should reply back to Coordinator from End device.
Present binding supports for only one-way communication. Not been working for two-way communication. example I will send packet from Coordinator to End Device like either S1=ON
or S1=OFF
here we should reply back to Coordinator from End Device like either S1=OFF
or S1=ON
So that what I need to updated?
Thanks, Amar.
Hi @g1velo ,
I should created a new java class for parsing incoming messages. Here existing parsing class method like this
public Tosr0xTparser(Thing thingToUpdate, XBeeMessage xbeeMessage)
In above method just pass the XBeeMessage xbeeMessage
parameter only ,but here in my case what i need to pass it?
my method like this: public Tosr0xTReceive(Thing thingToUpdate, String xbeeCommmand)
here one more doubt Is it required for passing the Xbee64bitaddress? Is it required for creating new Tosr0xTMsg class? how to represent the thing with the matching 64 bit address.
Please let me know
Thanks, Amar.
Hi @g1velo ,
See my method like this
if (thing.getThingTypeUID().equals(THING_TYPE_CAFE1000)) {
thingUIDToUpdate = thing.getUID();
thingToUpdate = thing;
Tosr0xTReceive tpr = new Tosr0xTReceive(thingToUpdate, xbeeMessage);
ArrayList<ChannelActionToPerform> listOfActionToPerform = tpr.getListOfChannelActionToPerform();
for (ChannelActionToPerform actionToPerform : listOfActionToPerform) {
logger.trace("channel to update : {} to value : {} ", actionToPerform.getChannelUIDToUpdate(),
actionToPerform.getState());
updateState(actionToPerform.getChannelUIDToUpdate(), actionToPerform.getState());
}
Here Tosr0xTReceive is java class for parsing incoming messages.
How to represent the thing with matching 64 bit Address ? Where to represent the thing with matching 64 bit Address in SNAVXbee2BridgeHandler.dataReceived(XBeeMessage) method ?
but it's doesn't work for me.
Thanks, Amar.
@amarpulli544 THe X64bitaddress is matched in an earlier if :
if (thing.getConfiguration().containsKey("Xbee64BitsAddress") && thing.getConfiguration().get("Xbee64BitsAddress").equals(xbeeAddressToLookup)) {
So... it should be already done. Feel free to add some logging to make sure that the match is occuring.
Just one remark class name you choose is not really the best you could have. Nothing really bad but you should choose a different name.
@g1velo
So that I need to update like this
if (thing.getThingTypeUID().equals(THING_TYPE_CAFE1000)) {
thingUIDToUpdate = thing.getUID();
thingToUpdate = thing;
Tosr0xTparser tp = new Tosr0xTparser(thingToUpdate, xbeeMessage);
ArrayList<ChannelActionToPerform> listOfActionToPerform = tp.getListOfChannelActionToPerform();
for (ChannelActionToPerform actionToPerform : listOfActionToPerform) {
logger.trace("channel to update : {} to value : {} ", actionToPerform.getChannelUIDToUpdate(),
actionToPerform.getState());
updateState(actionToPerform.getChannelUIDToUpdate(), actionToPerform.getState());
}
Is it right to update? I need to parsing incoming message in Tosr0xTparser class.
Thanks, Amar.
You need to create a new class just like the Tosr0xTparser but it has to be specific with what you want to do with your message, and only you know that. Your class could ne named something like : Cafe1000Parser, just a suggestion...
@g1velo
I will send the command like S1=ON
.
If S1=ON
then i need to send S1=OFF
from End Device to Coordinator/OH2. Here in my case we could also do the debugging and Coordinator receiving the data from End Device. But it will not update in karaf command.
So that i need to update this section only
if (xbeeMessage.getData().length == 2) {
// MSB + LSB temp = ( MSB*256 + LSB ) /16
// Given by TosR0xT Device
Byte msb = xbeeMessage.getData()[0];
Byte lsb = xbeeMessage.getData()[1];
float temperature = (msb.floatValue() * 256 + lsb.floatValue()) / 16;
ChannelActionToPerform channelActionToPerform = new ChannelActionToPerform();
channelActionToPerform.setChannelUIDToUpdate(new ChannelUID(thingUIDToUpdate + ":temperature"));
channelActionToPerform.setState(new DecimalType(temperature));
listOfChannelActionToPerform.add(channelActionToPerform);
}
Thanks, Amar.
@amarpulli544 Just to make sure : don't update the Tosr0xTparser class. Please create your own.
If your goal is just debugging and logging incoming message ( from end device to coordinator ), use logger.debug(.... ) in the if (thing.getThingTypeUID().equals(THING_TYPE_CAFE1000)) {
section.
@g1velo
I am not updating the Tosr0xTparser class. I need to create a java class like Tosr0xTparser class, but here make a some modifications. Here is incoming message means
if i will send S1=ON
message to End device from Coordinator/OH2.
Then i need to send message S1=OFF
to Coordinator/OH2 from End device.
Thanks, Amar.
Hello @g1velo ,
Coordinator unable to receive the packet from the End device while testing in Karaf Command prompt. It is been working fine in Eclipse IDE while testing in Debugging Mode or Runtime. Here i get the packet from end device like this
2017-03-10 13:40:44.103 [INFO ] [xbee.api.connection.DataReader:743 ] - [COM3 - 9600/8/N/1/N] Data received from 0013A20040E7782D >> 53 32 3D 4F 4E.
And User Interface also not update the state. (states ON or OFF). In Tosr0xTparser class you should comparing three sections like
if (xbeeMessage.getData().length == 7) {
ChannelActionToPerform channelActionToPerform = new ChannelActionToPerform();
channelActionToPerform.setChannelUIDToUpdate(new ChannelUID(thingUIDToUpdate + ":lights"));
channelActionToPerform.setState(new DecimalType(Double.valueOf(new String(xbeeMessage.getData()))));
// DecimalFormat twoDForm = new DecimalFormat("#.##");
// logger.debug(" Temp ::::: {} ", Double.valueOf(twoDForm.format(new String(xbeeMessage.getData()))));
// channelActionToPerform
// .setState(new DecimalType(Double.valueOf(twoDForm.format(new String(xbeeMessage.getData())))));
this.listOfChannelActionToPerform.add(channelActionToPerform);
}
2.
if (xbeeMessage.getData().length == 6) {
// MSB + LSB temp = ( MSB*256 + LSB ) /16
// Given by TosR0xT Device
Byte msb = xbeeMessage.getData()[0];
Byte lsb = xbeeMessage.getData()[5];
float temperature = (msb.floatValue() * 256 + lsb.floatValue()) / 16;
ChannelActionToPerform channelActionToPerform = new ChannelActionToPerform();
channelActionToPerform.setChannelUIDToUpdate(new ChannelUID(thingUIDToUpdate + ":lights"));
channelActionToPerform.setState(new DecimalType(temperature));
listOfChannelActionToPerform.add(channelActionToPerform);
}
3.
if (xbeeMessage.getData().length == 1) {
logger.info(" This is the relay State : "
+ HexUtils.prettyHexString(HexUtils.byteArrayToHexString(xbeeMessage.getData())));
// Instanciating the parser
Cafe1000msg t = new Cafe1000msg(xbeeMessage.getData());
// Collection<Channel> thingChannels = thing.getChannels();
for (Channel channel : thingChannels) {
ChannelActionToPerform channelActionToPerform = new ChannelActionToPerform();
if (channel.getUID().getId().contains("caferelay")) {
// logger.debug("updating : {} ", channel.getUID().getId());
// channelToUpdate = thingUIDToUpdate + ":" + channel.getUID().getId();
channelActionToPerform.setChannelUIDToUpdate(channel.getUID());
switch (channel.getUID().getId()) {
case "caferelay1":
// logger.debug("sss updating : {} to {} ", channelToUpdate, t.getRelay1State());
// this.state = t.getRelay1State();
channelActionToPerform.setState(t.getRelay1State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay2":
channelActionToPerform.setState(t.getRelay2State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay3":
channelActionToPerform.setState(t.getRelay3State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay4":
channelActionToPerform.setState(t.getRelay4State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay5":
channelActionToPerform.setState(t.getRelay5State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay6":
channelActionToPerform.setState(t.getRelay6State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay7":
channelActionToPerform.setState(t.getRelay7State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
case "caferelay8":
channelActionToPerform.setState(t.getRelay8State());
listOfChannelActionToPerform.add(channelActionToPerform);
break;
}
// logger.debug(" channel : {} {} ", thing.getThingTypeUID(), channel.getUID().getId());
}
}
}
here which section is going to be parse the incoming message? What is the length 7, 2 , 1 ?Once I will send packet to coordinator from end device not updating the User Interface in Eclipse IDE.
Here S1=ON
(turn ON Light) at User Interface.
I need to turn OFF (S1= OFF) the Light from End device.
Thanks, Amar.
@g1velo
I could create a cafe1000msg and Cafe1000parser classes for parsing incoming messages just like Tosr0xTparser and Tosr0xTMsg. Here I will send packet to End device from Coordinator . Receiving packet is Successfully. see as mentioned below
15:55:25.860 [DEBUG] [g.snavxbee2.handler.SNAVXbee2Handler] - sending to : S1 co
mmand ON
15:55:25.860 [DEBUG] [g.snavxbee2.handler.SNAVXbee2Handler] - handler xbee64Bit
sAddress : 0013A20040E7782D this.xbeeCommand : S1=ON
15:55:25.860 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - 111 Synced sendi
ng command : S1=ON to : 0013A20040E7782D
15:55:25.880 [DEBUG] [g.snavxbee2.handler.SNAVXbee2Handler] - handler xbee64Bit
sAddress : 0013A20040E7782D this.xbeeCommand : S1=ON
15:55:25.880 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - 111 Synced sendi
ng command : S1=ON to : 0013A20040E7782D
When I will send packet to Coordinator from End device. see as my log files
15:57:20.304 [INFO ] [ing.snavxbee2.devices.Cafe1000parser] - This is the relay
State : 53 31 3D 4F 46 46
15:57:20.307 [DEBUG] [inding.snavxbee2.devices.Cafe1000msg] - 01010011
15:57:20.308 [DEBUG] [inding.snavxbee2.devices.Cafe1000msg] - 00110001
15:57:20.308 [DEBUG] [inding.snavxbee2.devices.Cafe1000msg] - 00111101
15:57:20.308 [DEBUG] [inding.snavxbee2.devices.Cafe1000msg] - 01001111
15:57:20.308 [DEBUG] [inding.snavxbee2.devices.Cafe1000msg] - 01000110
15:57:20.309 [DEBUG] [inding.snavxbee2.devices.Cafe1000msg] - 01000110
15:57:20.310 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - Data received from
End Device
Thanks, Amar.
@amarpulli544
Amar, You have to create your own parser. You receive a message eg : "S1=ON" you have to send back object type ArrayList of ChannelActionToPerform => which has attribute channelUIDToUpdate and state
From here the Bridge will know what to do and will update the Item State.
@g1velo
Yes I created my own class. But here I can't understand the how to parsing message? this is the parsing code
channelActionToPerform.setState(new DecimalType(Double.valueOf(new String(xbeeMessage.getData()))));
Here I receive the value like this eg: " S1=OFF" (53 31 3D 4F 46 46)
Incoming message like this xbeeMessage = 53 31 3D 4F 46 46 getting the value in Hexa, then how can parsing incoming messaging to set state.
Thanks, Amar.
@amarpulli544
I see.
If you use xbeeMessage.getData(), you will be able to get the string value S1=0FF
Then that's you job to parse it correctly and detect which channel you have to update and which value State to assign to the channel..
@g1velo
I tried OnOfftype instead of DecimalType, but it won't work. I am facing the parsing issue in my case. Please let me know the how to parse it correctly.
Thanks, Amar.
String toto = new String(xbeeMessage.getData()) toto string should be : S1=0FF Parse toto variable
@g1velo
Thanks for suggestions. I will test with your suggestion and get back to you.
Thanks, Amar
Hi @g1velo ,
We did tested with parsing of incoming message, but here not updating the User Interface(Habpanel UI) Switch State. Here how to parsing of incoming message
if (xbeeMessage.getData().length == 6) {
ChannelActionToPerform channelActionToPerform = new ChannelActionToPerform();
channelActionToPerform.setChannelUIDToUpdate(new ChannelUID(thingUIDToUpdate + ":lights"));
String set = new String(xbeeMessage.getData());
channelActionToPerform.setState(new StringType(set));
this.listOfChannelActionToPerform.add(channelActionToPerform);
}
The above section do the parsing of incoming message correctly .
When I will send packet to End device from Coordinator, it's been working fine. see as my log files
11:51:21.896 [DEBUG] [g.snavxbee2.handler.SNAVXbee2Handler] - sending to : S1 co
mmand ON
11:51:21.896 [DEBUG] [g.snavxbee2.handler.SNAVXbee2Handler] - handler xbee64Bit
sAddress : 0013A20040E7782D this.xbeeCommand : S1=ON
11:51:21.897 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - 111 Synced sendi
ng command : S1=ON to : 0013A20040E7782D
11:51:21.899 [DEBUG] [g.snavxbee2.handler.SNAVXbee2Handler] - handler xbee64Bit
sAddress : 0013A20040E7782D this.xbeeCommand : S1=ON
11:51:21.899 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - 111 Synced sendi
ng command : S1=ON to : 0013A20040E7782D
Packet Receiving at End Device in XCTU.
When I will send packet from End Device to Coordinator , it's send successfully. But not updating User Interface (Habpanel UI) State. See as my log files while packet sending to Coordinator from End device
12:12:03.917 [DEBUG] [ing.snavxbee2.devices.Cafe1000parser] - xbeemsging length
: 6
12:12:03.918 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - Data received from
End Device
12:12:03.919 [TRACE] [xbee2.handler.SNAVXbee2BridgeHandler] - channel to update
: snavxbee2:cafe1000:gateway:0013A20040E7782D:lights to value : S1=OFF
Here I will turn ON Light from User Interface/ Coordinator, then I will turn OFF Light from End device. But not updating the Light State in User Interface (Habpanel UI).
Thnaks, Amar.
@g1velo
Here bridge handler get the data from end device like this
12:12:03.917 [DEBUG] [ing.snavxbee2.devices.Cafe1000parser] - xbeemsging length
: 6
12:12:03.918 [DEBUG] [xbee2.handler.SNAVXbee2BridgeHandler] - Data received from
End Device
12:12:03.919 [TRACE] [xbee2.handler.SNAVXbee2BridgeHandler] - channel to update
: snavxbee2:cafe1000:gateway:0013A20040E7782D:lights to value : S1=OFF
but it won't update state at user inteface (Habpanel UI). I thought we need to write some code stuff in Bridge Handler class for the update state. Here we need to send update state to Handler class from Bridge. It's my assumption. Please let me know the what is right way to do?
Thanks, Amar.
Hello @g1velo ,
We did finished receiving part in our binding. It's been working fine.Thanks for giving suggestions @g1velo . We will work on some other kind of items by using our binding.
Thanks, Amar.
Hi @amarpulli544 Cool ! btw : I have figured out why the command is sent twice to the end device and it will be corrected in a later version.
Hi @g1velo ,
I would like to add multiple items to the one channel like if i want control all type of items through one channel like S1 (SwitchItem, Number, Color,etc).
Item Name: States:
Switch ON,OFF
Number OPEN, CLOSE
Color ON,OFF, INCREASE,DECREASE
Here in our case S1 having a SwitchItem only. Data received part working fine. But here we get the some issue like this
Received update of a not accepted type (StringType) for item DemoSwitch
while receiving data from end device, here i am testing with both UI's (Classic UI, Basic UI). The Switch state is updated in Habpanel UI only.
Thanks, Amar.
About the UI not updating correctly, I would thing that the problem is outside the binding. To check run in karaf smarthome status Itemname This will let you know what is the value status, it could be a refresh problem.
For your main question, One channel can be linked to one Item which can be only one itemtype.
You have to handle this in the Thinghandler / handleCommand method just like you are doing it for the Switch itemtype
I probably don't really understand what you want to do.
We would like to control multiple item types through one channel like
Switch DemoSwitch "Switch" { channel = "snavxbee2:cafe1000:gateway:0013A20041268525:S1" }
Color DemoColor "democolor" { channel = "snavxbee2:cafe1000:gateway:0013A20041268525:S1" }
Number DemoDoor "demodoor" { channel = "snavxbee2:cafe1000:gateway:0013A20041268525:S1" }
I have done changes in thing-types.xml file
<channel-type id="S1">
<item-type>SwitchItem</item-type>
<label>SNAVXbee2 Binding switch Number 1</label>
<description>switch for SNAVXbee2 Binding</description>
</channel-type>
<channel-type id="S1">
<item-type>Color</item-type>
<label>SNAVXbee2 Binding switch Number 1</label>
<description>switch for SNAVXbee2 Binding</description>
</channel-type>
<channel-type id="S1">
<item-type>Number</item-type>
<label>SNAVXbee2 Binding switch Number 1</label>
<description>switch for SNAVXbee2 Binding</description>
</channel-type>
The above code are working for controlling multiple items types through one channel , Is it the right way of assigning?
Thanks, Amar.
Amar,
I think that one channel can be linked to one item/itemtype. You should create other channel S2 S3 ..... that will be linked other items/itemtypes
Hi @g1velo
We did tested on one channel can be linked multiple item/itemtype. It's working fine. Right now i am working on RGB Light control. We could solve the another issue is the end device getting packets twice. Now End device receiving one packet only .
Thanks, Amar.
Great ! Closing this issue !
Hello @g1velo,
I will send packets to End Device with updated source. But unable to receive any packets from Coordinator in XCTU. Here is in my case coordinator as a User Interface.
My Item Configuration file:
Switch XbeeDIO11switch "XbeeDIO11switch " (All) { channel = "snavxbee2:sample:gateway:0013A20041268525:DIO14" }
Here DIO14 is packet received port at End Device.
My Thing Configuration file:
Xbee End device Ports and Configuration values. Is that right configurations ?. see as mentioned below.
I/O settings Ports and Configure values :
Serial Interfacing Ports and Configure values:
Which port is suitable for sending packets to End device from Coordinator ?. When I changed the Light state from OFF to ON and I didn't get received any packets from Coordinator in XCTU. See as mentioned below my log files
What can I do for sending packets to End Device from UI ? Please let me know the how I can do.
Thanks, Amar.