Last Data Communication with a Node

In this case, we will need to join information from Frame and MeshHeader tables. Mesh Header contains information based on short address, first we need to find out the short address assigned to a node as shown before.

SELECT * FROM Frame,MeshHeader WHERE idframe=MeshHeader_idframe and ((OriginatorAddress = X'0005' and DestinationAddress = X'0000') OR (OriginatorAddress = X'0000' and DestinationAddress = X'0005'))

This statement queries all frames that have a Mesh Header where origin or destination is the selected node. If it is needed only the last frame, then it is needed to add the “ORDER BY idFrame DESC” clause and LIMIT the search to one row:

SELECT * FROM Frame,MeshHeader WHERE idframe=MeshHeader_idframe and ((OriginatorAddress = X'0005' and DestinationAddress = X'0000') OR (OriginatorAddress = X'0000' and DestinationAddress = X'0005')) ORDER BY idframe DESC LIMIT 1

Mesh Header can contain addresses in the form EUI64, therefore, the field has a type of BLOB. To select by these fields, data must by entered in hexadecimal format: X’----’.

It is possible to add results from different select statements to get, for example, all messages for a node, including route request/responses:

SELECT Frame.* FROM FRAME,MeshHeader where idframe = MeshHeader_idframe and ((OriginatorAddress = X'0005' and DestinationAddress = X'0000') OR (OriginatorAddress = X'0000' and DestinationAddress = X'0005'))
UNION
SELECT Frame.* FROM Frame,RREQ WHERE (RREQ.Originator = 5 OR RREQ.Destination = 5) and RREQ.RREQ_idFrame = Frame.idFrame
UNION
SELECT Frame.* FROM Frame,RREP WHERE (RREP.Originator = 5 OR RREP.Destination = 5) and RREP.RREP_idFrame = Frame.idFrame