This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using Z-Stack Gateway API in java

Hi

I want to create a gateway application by zigbee gateway API in java programming language .

Is any document for beginner?

My devices are cc2538EM+beaglebone black+cc2531dongle

This is my first code and it's output but i don't see any action:

code:

public class main
{
   public static void main(String [] args)
   {
      String serverName = "192.168.7.2";
      int port = 2533;
      Socket client=null;
      try
      {
         System.out.println("Connecting to " + serverName
                             + " on port " + port);
         client = new Socket(serverName, port);
         System.out.println("Just connected to "
                      + client.getRemoteSocketAddress());
         
         Gateway.DevSetOnOffStateReq.Builder onoff=Gateway.DevSetOnOffStateReq.newBuilder();
         Gateway.gwAddressStruct_t.Builder add=Gateway.gwAddressStruct_t.newBuilder();
         add.setIeeeAddr(0x00124B00040F0586L);
         add.setEndpointId(0x21);
         add.setAddressType(Gateway.gwAddressType_t.UNICAST);
         
         onoff.setDstAddress(add);
         onoff.setCmdId(Gateway.gwCmdId_t.DEV_SET_ONOFF_STATE_REQ);
         onoff.setState(Gateway.gwOnOffState_t.OFF_STATE);
         
         
         System.out.print(onoff.build().toString()+" Size:"+onoff.build().getSerializedSize()+" Out:");
         onoff.build().writeTo(System.out);
         System.out.println();
       
         OutputStream outToServer = client.getOutputStream();
         DataOutputStream out =
                       new DataOutputStream(outToServer);

//         out.write(onoff.build().getSerializedSize());
         onoff.build().writeTo(out);

         InputStream inFromServer = client.getInputStream();
         DataInputStream in =
                        new DataInputStream(inFromServer);
         while(true){
//        	 Gateway.DevGetOnOffStateRspInd.Builder onof=Gateway.DevGetOnOffStateRspInd.parseFrom(in).toBuilder(); 
//             System.out.println("response " + onof.toString());
         System.out.println("Server says " + in.read());
         }
         
      }catch(IOException e)
      {
         e.printStackTrace();
      }finally{
    	  try {
			client.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
      }
   }
}

Respones:

Connecting to 192.168.7.2 on port 2533
Just connected to /192.168.7.2:2533
cmdId: DEV_SET_ONOFF_STATE_REQ
dstAddress {
addressType: UNICAST
ieeeAddr: 5149013020968326
endpointId: 33
}
state: OFF_STATE

Server says 1
Server says 103
Server says 18
Server says 255
Server says 1
Server says 104
Server says 33
Server says 255


  • Hi,

    The gateway installation include a full API document, that is not language specific. You should use it as a reference to the available API.

    Also included are .proto files, which have the API definition in google-protobuf readable style. Using the respective protobuf engine (freely available on the web), language-specific API headers can be created (e.g. for C or for Java).

    The installer also include a sample application (full C source provided), to demonstrate the use of the various APIs. I assume you are familiar with Java and C, so porting the concepts from the C sample-app to java should be streight forward. if you have some specific questions, feel free to post them here.

    (If your question was about generic jJava documents for beginners, there are plenty available on the web, and this is however outside the scope of this forum).

    Best regards,

    OD

     

  • I have just made a JAVA Example for the ZStack-Linux-Gateway available on git.ti.com:
    git.ti.com/.../ti-zstack-linux-gateway-java-cmdline-example

    The example includes the protobuf-java modules for the gateway network manager and the hagateway .proto files, which where generated using protobuf java compiler. The example wraps some of the commonly used protobuf API's and allows them to be called from a shell. The commands exposed are:

    Network management control plain API's:
    • NWK_SET_PERMIT_JOIN_REQ
    • NWK_GET_DEVICE_LIST_REQ
    • NWK_REMOVE_DEVICE_REQ

    GW Data Plain API's:
    • GW_READ_DEVICE_ATTRIBUTE_REQ
    • GW_WRITE_DEVICE_ATTRIBUTE_REQ
    • GW_READ_DEVICE_MSP_ATTRIBUTE_REQ
    • GW_WRITE_DEVICE_MSP_ATTRIBUTE_REQ
    • DEV_SET_ONOFF_STATE_REQ
    • DEV_GET_ONOFF_STATE_REQ
    • DEV_SET_LEVEL_REQ
    • DEV_GET_LEVEL_REQ
    • DEV_SET_COLOR_REQ
    • DEV_GET_COLOR_REQ
    • DEV_GET_TEMP_REQ
    • DEV_THERMOSTAT_SETPOINT_CHANGE_REQ

    Hopefully this will give you a good starting point for developing a java application.

    The ota server protobuf-java module was not created, if this is needed you should follow these instructions developers.google.com/.../javatutorial

    regards,
    TC.
  • Wow, this is wonderful.
  • Thank you very much for your efforts on this issue.