Connect to Azure IoT Hub with Java Paho -
we have started poc connect of our existing code azure iot hub via mqtt test azure’s support standard protocols , tools. using paho client getting connack return code of 5 – not authorized.
we followed instructions on how setup iot hub , created 1 using f1 (free) scale tier. followed another azure document , downloaded device explorer, created device , generated sas token. plugged paho:
public static void main( string[] args ) { string deviceid = "device-fcbd127a"; string sastoken = "sharedaccesssignature sr=coyoteiot.azure-devices.net%2fdevices%2fdevice-fcbd127a&sig=3acrhqxxxxxxxxxxxzg%3d&se=1468067737"; string brokeruri = "ssl://coyoteiot.azure-devices.net:8883"; string clientid = deviceid; system.out.println( "connecting " + brokeruri +" "+clientid); mqttasyncclient client = null; try { client = new mqttasyncclient( brokeruri, clientid ); if ( client != null ) { mqttconnectoptions options = new mqttconnectoptions(); client.setcallback( new azurecallback() ); options.setusername( "coyoteiot.azure-devices.net/device-fcbd127a" ); options.setpassword( sastoken.tochararray() ); imqtttoken token = client.connect( options ); token.waitforcompletion( 5000 ); if ( client.isconnected() ) { system.out.println( "success!" ); } else { system.out.println( "could not connect azure iot hub, timed-out" ); } } } catch ( mqttexception e ) { client.getdebug().dumpbasedebug(); e.printstacktrace(); } { if ( client != null ) { try { client.disconnect(); } catch ( mqttexception ignore ) {} } } }
we have confirmed wireshark ssl connection made azure , connect packet sent. see connack return code of 5 being sent paho , azure dropping connection thereafter. looked “shared access policies” , tried different settings. there nothing in audit logs , have “verbose” turned on everything.
has connected paho (or other third-party java client) azure iot hub?
where find diagnostic information can troubleshoot ourselves?
on side note, shelved (mqtt) approach , tried connect via rest services , receive more ambiguous “500-internal server error“ response. makes think there more fundamental access issue here. f1 scale hub support microsoft sdk? there hidden access control settings missing? format of names strict, not allowing characters or case?
apparently had issues device explorer utility. instead of generating sas token expiry of 365 days, generated token 365 seconds.
note se=1468067737
in sas token, evaluates expiration of jul 09 08:35:37 edt 2016, past our test execution.
Comments
Post a Comment