Skip to content

Commit

Permalink
- include RSSI value in generated messages
Browse files Browse the repository at this point in the history
  • Loading branch information
owagner committed Mar 14, 2015
1 parent d31dea3 commit 773eaef
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 41 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The message format generated is a JSON encoded object with the following members
* val - the actual value, in numeric format
* eno_srcid - when sending message, eno2mqtt fills in the source ID of the sending device.
This field is ignored on incoming messages.
* eno_dbm - the RSSI value of the received message


EEP specifics
Expand Down Expand Up @@ -137,6 +138,7 @@ Changelog
- renamed property eno.usb300 to the more accurate eno.tcm
- added eno.setRepeater to set the repeater mode of the TCM
- more detailed log output about received frames (including dest ID, RSSI and status flags)
- include RSSI value in generated messages

* 0.2 - 2015/03/12 - owagner
- now supports F6-02 and F6-03 EEPs (rocker switches)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/tellerulam/eno2mqtt/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public String getHexID()

public synchronized Map<String,Object> getStates()
{
return new HashMap<>(state);
if(state!=null)
return new HashMap<>(state);
else
return null;
}

public synchronized Object getState(String key)
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/tellerulam/eno2mqtt/MQTTHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,17 @@ public void connectionLost(Throwable t)
Main.t.schedule(new StateChecker(),30*1000,30*1000);
}

private void doPublish(String name, Object val, String src,boolean retain)
private void doPublish(String name, Object val, String src,boolean retain,int dbm)
{
JsonObject jso=new JsonObject();
jso.add("eno_srcid",src);
if(val instanceof Integer)
jso.add("val",((Integer)val).intValue());
else if(val instanceof Float)
jso.add("val",((Float)val).floatValue());
else
jso.add("val",val.toString());
jso.add("eno_srcid",src);
jso.add("eno_dbm",-dbm);
String txtmsg=jso.toString();
MqttMessage msg=new MqttMessage(jso.toString().getBytes(StandardCharsets.UTF_8));
msg.setQos(0);
Expand Down Expand Up @@ -181,13 +182,13 @@ public static void setEnoceanConnectionState(boolean connected)
}
}

public static void publish(String name, Object val, String src,boolean retain)
public static void publish(String name, Object val, String src,boolean retain,int dbm)
{
instance.doPublish(name,val,src,retain);
instance.doPublish(name,val,src,retain,dbm);
}
public static void publish(String name, Object val, String src)
public static void publish(String name, Object val, String src,int dbm)
{
instance.doPublish(name,val,src,true);
instance.doPublish(name,val,src,true,dbm);
}

}
23 changes: 1 addition & 22 deletions src/main/java/com/tellerulam/eno2mqtt/TCM310Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,7 @@ private void dispatchERP1Packet(ESP3ERP1Packet p,ExtendedInfo ei)
L.warning("ERP1 packet from unknown device "+Long.toHexString(p.senderID)+" ignored, please update your device list file!");
return;
}
d.eep.handleMessage(d,p);
}

private static class ExtendedInfo
{
int subTelNum;
long destinationID;
int dBm;

@Override
public String toString()
{
StringBuilder s=new StringBuilder();
s.append('{');
s.append(subTelNum);
s.append('@');
s.append(Long.toHexString(destinationID));
s.append('-');
s.append(dBm);
s.append("dBm}");
return s.toString();
}
d.eep.handleMessage(d,p,ei);
}

private void parseERP1(byte b[],byte op[])
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/tellerulam/eno2mqtt/eep/EEP.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,31 @@ public static EEP findBySpec(String eepspec)
}
}

public abstract void handleMessage(Device d,ESP3ERP1Packet p);
public abstract void handleMessage(Device d,ESP3ERP1Packet p,ExtendedInfo ei);

protected void assertPacketType(ESP3ERP1Packet p,Class<? extends ESP3ERP1Packet> whichPacket)
{
if(p.getClass()!=whichPacket)
throw new IllegalArgumentException("Got unexpected packet type "+p.getPacketType()+" for profile "+this);
}

protected void publish(Device d,Object val)
protected void publish(Device d,Object val,int dbm)
{
MQTTHandler.publish(
d.name,
val,
d.getHexID()
d.getHexID(),
dbm
);
}
protected void publish(Device d,String suffix,Object val,boolean retain)
protected void publish(Device d,String suffix,Object val,boolean retain,int dbm)
{
MQTTHandler.publish(
d.name+'/'+suffix,
val,
d.getHexID()
d.getHexID(),
retain,
dbm
);
}
}
8 changes: 3 additions & 5 deletions src/main/java/com/tellerulam/eno2mqtt/eep/EEP_F602xx.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.tellerulam.eno2mqtt.eep;

import java.util.*;

import com.tellerulam.eno2mqtt.*;
import com.tellerulam.eno2mqtt.esp3.*;

Expand All @@ -18,7 +16,7 @@ public EEP_F602xx(int appStyle)

@SuppressWarnings("boxing")
@Override
public void handleMessage(Device d, ESP3ERP1Packet p)
public void handleMessage(Device d, ESP3ERP1Packet p,ExtendedInfo ei)
{
assertPacketType(p,ESP3ERP1_RPSPacket.class);

Expand All @@ -37,7 +35,7 @@ public void handleMessage(Device d, ESP3ERP1Packet p)
else
key=buttons[r];

publish(d,key,1,false);
publish(d,key,1,false,ei.dBm);
d.setState("PRESSED"+key,Boolean.TRUE);
}
else
Expand All @@ -49,7 +47,7 @@ public void handleMessage(Device d, ESP3ERP1Packet p)
{
if(d.getState(key)==Boolean.TRUE)
{
publish(d,key.substring(7),0,false);
publish(d,key.substring(7),0,false,ei.dBm);
d.setState(key,Boolean.FALSE);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tellerulam/eno2mqtt/eep/EEP_F61000.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class EEP_F61000 extends EEP
{
@SuppressWarnings("boxing")
@Override
public void handleMessage(Device d, ESP3ERP1Packet p)
public void handleMessage(Device d, ESP3ERP1Packet p,ExtendedInfo ei)
{
assertPacketType(p,ESP3ERP1_RPSPacket.class);

Expand All @@ -22,7 +22,7 @@ else if(v==13)
else if((v&13)==12)
v=1;

publish(d,v);
publish(d,v,ei.dBm);
}

}
22 changes: 22 additions & 0 deletions src/main/java/com/tellerulam/eno2mqtt/esp3/ExtendedInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tellerulam.eno2mqtt.esp3;

public class ExtendedInfo
{
public int subTelNum;
public long destinationID;
public int dBm;

@Override
public String toString()
{
StringBuilder s=new StringBuilder();
s.append('{');
s.append(subTelNum);
s.append('@');
s.append(Long.toHexString(destinationID));
s.append('-');
s.append(dBm);
s.append("dBm}");
return s.toString();
}
}

0 comments on commit 773eaef

Please sign in to comment.