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,270 points
1,501 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,280 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,620 points
1,552 views
0 votes
1 answer

KAA server : Is it possible to develop an application to communicate with routers using PHP

It's actually not possible to develop a ...READ MORE

answered Jan 10, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
478 views
0 votes
1 answer
0 votes
0 answers
0 votes
0 answers
0 votes
0 answers

ionic build ios error ( ionic cordova build ios )

When i run "ionic cordova build ios" ...READ MORE

Nov 15, 2022 in Mobile Development by gaurav
• 23,260 points
571 views
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,280 points
1,548 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,280 points
1,306 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,280 points
2,142 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP