Communicating with nearby devices - firefox-os

I want to develop a FirefoxOS privileged app that can send text messages to nearby devices.
Android app can use Bluetooth or Wifi P2P. But FirefoxOS privileged apps cannot use Bluetooth/Wifi API. These are only available for certified apps.
Privileged apps can use TCP socket API. Is this the only way?
Is there any way to get available IP addresses on LAN?

#Kazhik, unfortunately right now, that is the only way to go. And the explanation for that is that by using the socket API you can implement any protocol on top of TCP, such as IMAP, IRC, POP, HTTP, etc., or even build your own to sustain any specific needs you could have.
Since certified apps can only be included by the oem, access to Bluetooth or WiFi information API aren't a viable option now.

At today's date (September 18, 2015) the WebIDE supports installing certified apps in older Firefox OS versions like 1.3 and in physical devices.
I tried installing the Gaia test apps (these are certified) in one Alcatel OT FireC and everything worked perfectly fine ;)

DNS-SD (part of the Zeroconf specification) allows you to broadcast and receive "advertisements" from other devices on the local network. That requires UDP and TCP permissions, which means a "privileged" app, as you thought. That's not a problem, unless you need to distribute the app outside of the Firefox Marketplace.
There's an implementation of DNS-SD for JavaScript at https://github.com/justindarc/dns-sd.js
For compatibility with other messaging apps, you might want to implement XMPP:
http://www.xmpp.org/extensions/xep-0174.html

Related

WebUSB for connecting to custom hardware

I would like to talk to a custom piece of hardware via my web application using WebUSB
The hardware is already able to communicate to a python script running on a laptop via USB
Now I have 2 questions and I hope you can help me :)
Does the hardware need to implement anything WebUSB specific? Or is the USB communication that is already implemented enough?
Is WebUSB ready for production? This application will be used by customers to talk to machines like excavators.
The whole application (talking to machines) already works via internet - we just need to implement the USB communication to handle the case that the user doesn't have a working internet connection.
best,
Kev
Does the hardware need to implement anything WebUSB specific? Or is the USB communication that is already implemented enough?
It is enough.
Is WebUSB ready for production? This application will be used by customers to talk to machines like excavators.
The Chrome team takes the decision to make a Web API available to developers very seriously and is committed to supporting these APIs for the long term. The draft status of the WebUSB API should not be taken as a reflection of the Chrome team commitment to this work. It is a necessary effect of how the web standardization process works.
The WebUSB API has been available for quite some time and is considered stable. While we have been making steady investments in the implementation of the API there are no changes to the developer-facing interface planned.

Connect to USB RFID reader with browser

I am a newbie dev trying to build a web application that can read and write to an RFID Card through the browser.
I am currently using an ACR122U Card Reader and have gotten it reading directly to my server in NodeJS with the nfc-pcsc node package.
Of course, I don't want to have my users have to run their own server and install a ton of libraries to read a card.
Ideally, they can just plug a card reader into their USB port and communicate from USB>Browser>Node Server and back again.
Can anyone recommend a good way to communicate with a USB RFID reader through the browser (and send to backend server?). Thanks
As far as I know, at the moment (Mar.2021) there is only experimental support for USB in browsers (WebUSB API). Please refer to https://developer.mozilla.org/en-US/docs/Web/API/USB
As this API is experimental, you may not want to rely on it for production. In this case, a component running on end users machine will be needed (e.g. a more or less simple service that responds via https at 'localhost'. This approach opens several usability/security concerns (such as supplying a trusted certificate for localhost, properly managing CORS headers etc).
You may want to refer to this question for additional suggestion: Architectures to access Smart Card from a generic browser? Or: How to bridge the gap from browser to PC/SC stack?

Integrating HomeKit devices with Node-RED

node-red-contrib-homekit is a slick way to create virtual HomeKit devices in Node-RED, providing a bridge to non-HomeKit-aware hardware.
When it is time for my Node-RED flows to talk to real HomeKit devices, however, it seems to get messy.
To control a HomeKit device (thermostat, outlet, bulb, occupancy sensor, etc.) from a Node-RED flow, the most elegant solution I know of is to install Homebridge and something like homebridge-mqtt alongside Node-RED, which feels to me like a big, awkward hammer.
I feel like I'm missing something--is there a more direct approach? Or am I doing it in an advisable way?
As far as I know, there is no way to talk from Node-RED to HomeKit enabled devices using the HomeKit protocol. Apple only publish the specs for client devices and services, but the HomeKit server, and therefore UI, can only be iOS device. You can think of HomeKit as the Apple alternative to Node-RED. And the control can only be one way - from Homekit to Node-RED. You can make the data flow both ways though. For instance you can create virtual HomeKit switch in Node-RED, that the Home app can control using automation (like turning on when you're home). Thus you can have binary communication between them.
The protocol actually specifies a set of predefined accessories with their options and capabilities, and each manufacturer should provide API for the selected accessory. One physical device can have multiple virtual accessories - like temp and humidity sensors, that are shown as two items in Home app, but might be one actual device.
You need to use your iPhone/iPad to add and control the bridge/accessories, that you can create in Node-RED or are licensed HomeKit devices. But they are not able to talk to each other using that protocol. You'd have to find alternative way for doing this by looking for another API by the manufacturer. For instance Hue is certified as HomeKit and you can add it to your Home app directly, but if you want to control it with Node-RED you'd need their other API as the HomeKit server is proprietary.
Also for Node-RED use the updated node-red-contrib-homekit-bridged that can simplify your management.
I’m in the process of changing my setup from the node-red Homekit node to a separate Homebridge with the MQTT plugin myself. Not only because it is more elegant but also more flexible HomeKit-wise, provides a “separation of concerns” between processes running, and also let’s me just add one bridge to Home app.
There’s also a websocket plugin for Homebridge which also plays nice with node-red but as I have a mosquitto MQTT broker running anyway I might as well use the “language of IoT”.
I am in the process of connecting Homekit related devices and services with Node-RED using Homebridge. Both Homebridge and Node-RED can be installed on the same machine (a Pi).
There are several plugins available to connect Homebridge with Node-RED and maybe you can create a flow that then controls your devices for which you also have to find a plugin in Node-RED. It may be a bit over engineered as there are tons of plugins available for Homebridge directly but using Node-RED is much more fun. The MQTT way is also a good start but I didn't want to mess with protocols and stuff.

Is it possible to connect to Sony Camera Remote API with hybrid mobile apps

Since we need to have a UDP socket to discover the device, and since javascript seems not supporting UDP, is it possible to connect to Sony Camera Remote API with a javascript based mobile app (non native).
As said in the comments, you can use Cordova to do the SSDP discovery.
However, as far as I can see, the API is HTTP-based. So if you don't need discover (can write in the IP address and port manually), then this should be possible to do.
Did you ever get anywhere with this project? I'd be interested in getting some LiveView and controlling a camera using Javascript.

Why does Google Cast Chrome extension only search for link-local devices via mDNS?

Chromecast v2 devices announce their presence using mDNS, and they are discoverable when performing mDNS queries for _googlecast._tcp.
DNS-SD / Bonjour also support the concept of "wide-area discovery", which makes use of standard unicast DNS queries to find devices. This can be useful for more complex networking scenarios - i.e your Chromecast devices may be in one VLAN but your sender devices are in another.
However, when trawling Chromium source I found this code in mdns_api.cc which seems to indicate that the Chrome extension will only search for _googlecast._tcp.local - completely preventing wide-area DNS discovery of other Chromecast devices. Based on anecdotal testing, it seems the Chromecast iOS app and SDK also have this behaviour.
Why does the official discovery mechanism for the Chromecast Chrome extension explicitly only discover link-local Chromecast devices?
They probably didn't do "wide-area discovery" because there are a lot of gotchas in implementing it and there isn't much gain to be had.
Let's suppose that they did implement it (from looking at the spec, it doesn't seem to be technically difficult; seems like it is mostly an edge-case problem).
You'd need:
A domain under your control. Could be a local-only domain.
Not many people do this.
Multiple VLANs that you want to use.
Most homes only have a single VLAN.
A DNS-SD server that supports Wide-Area Discovery.
This is probably the easiest thing to have. Even then, most people wouldn't do it.
A UX flow to input the various WAD servers that you want to ping for devices.
This is the hard part for Google since it needs to be consistent across all SDKs and using a WAD-discovered Chromecast would cause all local-media-server Apps to not work (e.g. Plex).
(1) - (3) are why Google wouldn't make this a priority. Chromecast is, after all, a consumer device and consumers tend to have simple networking situations. (4) is why it isn't low-hanging fruit.
You'd also need to solve a few problems:
What happens when you are connected to a Chromecast on a separate VLAN and then remove it's WAD server?
What if the WAD server goes offline?
What happens when you have multiple Chromecasts with the same name?
What if they also have the same IP address (possible since VLANs can have overlapping IP spaces)?
What happens when a Chromecast is discoverable using WAD but not reachable?
Should they attempt a connection to every single Chromecast you discover to test that it is reachable?
How would you scale this out to work with 100s of Chromecasts in VLANs that could be "far" away?
It is these problems that I think would prevent Google from implementing WAD even if they wanted to.

Resources