Unable to communicate to device with .local domain using android, corova-zeroconf-plugin

0 votes

I am having an iot device which is advertising in my network with name iotdevice.local, i am able to send http requests to this domain in my windows pc after installing Bonjour. But i am developing an ionic app from which i'll be communicating frequently with this device. So i am using cordova-zeroconf-plugin. (https://www.npmjs.com/package/cordova-plugin-zeroconf). I am seeing the services when i add watch for .local services. but my requestis faield when i use iotdevice.local in $http function. I have this code App.js

if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);
  console.log("device ready");
  var zeroconf = cordova.plugins.zeroconf;
  zeroconf.watch('_http._tcp.local.', function(result) {
    var action = result.action;
    var service = result.service;
    console.log(JSON.stringify(result));
    if (action == 'added') {
        console.log('service added', service);
    } else {
        console.log('service removed', service);
    }
  });


}

It works fine and in logs i see my device

{"action":"added","service":{"application":"http","domain":"local","port":80,"name":"iotdevice","server":"iotdevice.local.","description":"\00","protocol":"tcp","qualifiedname":"iotdevice._http._tcp.local.","type":"_http._tcp.local.","txtRecord":{},"addresses":["192.168.0.4"],"urls":["http://192.168.0.4:80"]}}

But when i use this in controller.js-

$scope.sendRequest2 = function(){
    $http({
      method: 'GET',
      url: 'http://iotdevice.local/events?id=600194067eba&action=socket1off'
    }).then(function successCallback(response) {
        $scope.req2succes=true;
        console.log("Sent");
      }, function errorCallback(response) {
        console.log(JSON.stringify(response));
        console.log("Could not Sent");
        $scope.req2succes=false;
      });
  }

It Doesn't work. Request status is always -1. can anyone help me how i can deal with his. Am i doing something fundamentally wrong ?

Aug 2, 2018 in IoT (Internet of Things) by Matt
• 2,260 points
278 views

1 answer to this question.

0 votes

Use IP address instead of http://iotdevice.local..Use http://192.168.0.4:80.Hope this works.

answered Aug 2, 2018 by anonymous2
• 4,260 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

To communicate with multiple BLE devices using Windows 10 UWMP

Not fully sure if you are wanting ...READ MORE

answered Oct 8, 2018 in IoT (Internet of Things) by Upasana
• 8,550 points
308 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Downloading source code of Android Things

No because AndroidThings is still in preview ...READ MORE

answered Jul 5, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
521 views
0 votes
1 answer

Creating Android Things' bundle and pushing it over OTA

Here are all the steps necessary to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
48 views
0 votes
1 answer

AWS IoT - Access shadow through .Net, REST, with certificate

If you want to publish and/or subscribe ...READ MORE

answered Jul 25, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
110 views
0 votes
1 answer

Android AllJoyn: Connection with second machine gives error of BusAttachement

Why dont you create two Interfaces, one ...READ MORE

answered Jul 25, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
45 views
0 votes
1 answer

Publishing commands to device in IBM IoT using MQTT in Java

If you are publishing from an application, ...READ MORE

answered Jul 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
456 views
0 votes
1 answer

Integrate IoT device to Azure using MQTT

Today there isn't an official support for ...READ MORE

answered Sep 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
756 views