TheThingsArchive / java-app-sdk

The Things Network Application SDK for Java
MIT License
30 stars 25 forks source link

onActivation event not happens #57

Closed wireless-road closed 3 years ago

wireless-road commented 6 years ago

Hello! I am using java-app-sdk to catch events of end-devices. Here is code:

        Client client = new Client(region, appId, accessKey);

        client.onError((Throwable _error) -> log.warning("error: " + _error.getMessage()));

        client.onConnected((Connection _client) -> log.info("connected !"));

        client.onActivation((String devId, ActivationMessage data) -> {
            log.info("\r\n====================================\r\n"
                    + "AppEui: " + data.getAppEui()
                    + "DevEui: " + data.getDevEui());
    });

        client.onMessage((String devId, DataMessage data) -> {
            log.info("\r\n###############################"
                        + "\r\nMessage from device " + devId + " with: "
                        + "\r\nAppId: " +  ((UplinkMessage)data).getAppId()
                        + "\r\nDevId: " + ((UplinkMessage)data).getDevId()
                        + "\r\nCounter: " + ((UplinkMessage)data).getCounter()
                        + "\r\nHWserial: " + ((UplinkMessage)data).getHardwareSerial()
                        + "\r\nPort: " + ((UplinkMessage)data).getPort()
                        + "\r\nDataRaw: " + bytesToHex(((UplinkMessage)data).getPayloadRaw())
                        + "\r\nGateway: " + ((UplinkMessage)data).getMetadata().getGateways().get(0).getId());

            DownlinkMessage responce = new DownlinkMessage(((UplinkMessage)data).getPort(), "hello");
            log.info("Sending");
            try {
                client.send(devId, responce);
            } catch (Exception e) {
                log.warning("Responce failed: " + e.getMessage());
            }
        });

        client.start();

I able to catch uplink (onMessage) events as well as onConnected but no luck with onActivation events. I unable to catch them. Here is sequence while trying to catch activation event:

  1. gateway stopped
  2. end device deleted from application on TTN server
  3. java-app-sdk started
  4. end device added to applicatioin on TTN server
  5. gateway started
  6. end device started

Join procedure passes succesfully (as well as activation on TTN): capture3 but only uplink messages catched using onMessagehandler:

июн 22, 2018 10:36:27 PM org.thethingsnetwork.samples.mqtt.App lambda$main$3
INFO: 
###############################
Message from device 06c7cbb9 with: 
AppId: 1011762258891737
DevId: 06c7cbb9
Counter: 0
HWserial: 343934354C377416
Port: 2
DataRaw: 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 
Gateway: eui-aa555a0000000005
июн 22, 2018 10:36:27 PM org.thethingsnetwork.samples.mqtt.App lambda$main$3
INFO: Sending
июн 22, 2018 10:36:33 PM org.thethingsnetwork.samples.mqtt.App lambda$main$3
INFO: 
###############################
Message from device 06c7cbb9 with: 
AppId: 1011762258891737
DevId: 06c7cbb9
Counter: 1
HWserial: 343934354C377416
Port: 2
DataRaw: 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 
Gateway: eui-aa555a0000000005
июн 22, 2018 10:36:33 PM org.thethingsnetwork.samples.mqtt.App lambda$main$3
INFO: Sending