Paho cannt connect to a wireless network [message #1670659] |
Fri, 13 March 2015 09:32 |
Amr Mising name Messages: 3 Registered: December 2011 |
Junior Member |
|
|
I am developing an Android App and using Paho MQTT library. the App is based on the current WiFi state and the currently connected network, so this means that i am using a WiFi receiver to monitor the WiFi states.
The problem is, in my own PC, when I run the App, it detected the network and connects to the it and it works fine. But, when I tried to connect the App to a telemetry Box which is also connected to the network, the App cant neither detect not connect to the network.
Any suggestions why that is happening? please have a lok at the code posted below shw how i connect to network
**code**:
int wifiExtras = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
//WifiManager wifiMgr = (WifiManager) context.getSystemService(WiFi_Service);
switch (wifiExtras) {
case WifiManager.WIFI_STATE_ENABLING:
MQTTPrimaryReceiverLocked = true;
Log.i(TAG, "@MQTTPrimaryConnectReceiver(): WIFI_STATE_ENABLING");
MQTTPrimaryReceiverT1 = new Timer();
MQTTPrimaryReceiverT1.schedule(new MQTTReceiverLockTimedTask(), RELEASE_MQTT_RECEIVER_LOCK_AFTER);
timer1Scheduled = true;
break;
case WifiManager.WIFI_STATE_ENABLED:
MQTTPrimaryReceiverLocked = true;
Log.i(TAG, "@MQTTPrimaryConnectReceiver(): WIFI_STATE_ENABLED");
MQTTPrimaryReceiverT2 = new Timer();
MQTTPrimaryReceiverT2.schedule(new MQTTReceiverLockTimedTask(), RELEASE_MQTT_RECEIVER_LOCK_AFTER);
timer2Scheduled = true;
interNetConnectivityModule();
break;
case WifiManager.WIFI_STATE_DISABLING:
MQTTPrimaryReceiverLocked = true;
Log.i(TAG, "@MQTTPrimaryConnectReceiver(): WIFI_STATE_DISABLING");
MQTTPrimaryReceiverT3 = new Timer();
MQTTPrimaryReceiverT3.schedule(new MQTTReceiverLockTimedTask(), RELEASE_MQTT_RECEIVER_LOCK_AFTER);
timer3Scheduled = true;
break;
case WifiManager.WIFI_STATE_DISABLED:
MQTTPrimaryReceiverLocked = true;
Log.i(TAG, "@MQTTPrimaryConnectReceiver(): WIFI_STATE_DISABLED");
Log.i(TAG, "@MQTTPrimaryConnectReceiver(): No InterNet Connectivity.");
Toast.makeText(getApplicationContext(), "WIFI_STATE_DISABLED.", Toast.LENGTH_SHORT).show();
MQTTPrimaryReceiverT4 = new Timer();
MQTTPrimaryReceiverT4.schedule(new MQTTReceiverLockTimedTask(), RELEASE_MQTT_RECEIVER_LOCK_AFTER);
timer4Scheduled = true;
if ( (MQTTConnModuleWasCalled) && (!reconnectTimerCurrentlyActive) ) {
MQTT_Reconnect_Module(WiFi_OFF);
} else if (!MQTTConnModuleWasCalled) {
WiFiUtility.turnWiFiON(getApplicationContext());
}
break;
case WifiManager.WIFI_STATE_UNKNOWN:
MQTTPrimaryReceiverLocked = true;
Log.i(TAG, "@MQTTPrimaryConnectReceiver(): WIFI_STATE_UNKNOWN");
MQTTPrimaryReceiverT5 = new Timer();
MQTTPrimaryReceiverT5.schedule(new MQTTReceiverLockTimedTask(), RELEASE_MQTT_RECEIVER_LOCK_AFTER);
timer5Scheduled = true;
break;
**Code2 **:
protected void interNetConnectivityModule() {
// TODO Auto-generated method stub
Log.w(TAG, "@interNetConnectivityModule().");
ConnectivityManager mConnMgr = (ConnectivityManager)getSystemService(Network_Service);
if (mConnMgr != null) {
NetworkInfo networkInfo = mConnMgr.getActiveNetworkInfo();
if (networkInfo != null) {
switch(networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
if (networkInfo.isConnected()) {
Log.i(TAG, "@interNetConnectivityModule(): Connected");
preMQTTConnChecks();
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25262 seconds