What is the best way to determine the connection state of an AWS IoT device? - aws-iot

How can I determine if a particular AWS IoT device is currently online? I could send an MQTT message and make the device answer it. But is there some implicit way on seeing if a device is online/connected?

You can also use Fleet Indexing with enabled Connectivity Indexing
https://docs.aws.amazon.com/iot/latest/developerguide/managing-index.html and do search for your deviceId. In results you can check connectivity. Also you can search for all connected devices by using search with query connectivity.connected:true

Ok, there is a dedicated internal MQTT topic for it. Subscribe to $aws/events/presence/# to get presence events for all your devices.

Related

aws_sdk: how can I identify if my device is connected to the aws server

I have a device (esp32s2) which is IoT enabled and communicating with AWS server.
The device is connecting to the internet via router. I want to check from the device, if the router is connected to the internet or not. If not connected, I need to disconnect mqtt broker instantly.
I know there is aws_iot_yield happening, but it is taking too much of time to change the client state (~5-10 mins) after disconnection. So, is there is any other way in which I can come to know if the device is connected to the mqtt broker or not using AWS sdk?
I want to avoid using pinging to some address/server as it will increase the usage of resources.
Thanks in advance!
Since the connectivity to the AWS server trough internet depends on the network elements, the only reliable way to know if you are connected to internet is to send a package to a know address and receive the response. Simplest way to do this is to use ICMP (ping) protocol. Usually the most reliable destination to ping is the Google DNS server 8.8.8.8 or 8.8.4.4 which is a cluster service and it's always replying on the ping.
You can control the pause between two pings and how many pings you will send in one session in order to preserve the resources.
Alternative approach is to use a router that can send messages to a monitoring device that the link state was changed (by example SNMP trap). But this is not fully reliable method since the router can not detect all scenarios where the connectivity to your AWS server is lost.

Is it possible to have more than one simultaneous connection to the specified IoT Watson device via the MQTT client?

A unique client id having a specific format (d:organizationID:deviceType:deviceID) is used for connection to MQTT in IoT Watson.
It looks that only one unique MQTT connection is allowed per client id to a specific device.
For some cases is required to have more than one simultaneous MQTT connection to the specific device inside the organization account, e.g., in the case of scaling of services integrated with the IBM Watson platform (i.e. clustering).
The question will be, is there the possibility to have more than one simultaneous MQTT connection to the specific device inside the organization account?
For example, by having the possibility to generate a client id or some part of the client id?
It is not possible for devices. The clientId has to be unique as you said and so any existing connection using that clientId would be disconnected when the new connections is made. I am not quite sure I understand the use case you mention with clustering, as the one connection should be fine for a device.
If you have an application rather than a device then you can create a "Scalable Application" as mentioned here https://www.ibm.com/docs/en/watson-iot-platform?topic=applications-communicating-mqtt which extends the clientId.

WebRTC and authentication implementations

Ok so recently I have been in need of creating a application with WebRTC for video voice etc.
So after looking into some libraries I found SimpleWebRTC to be pretty handly looking:
https://github.com/andyet/SimpleWebRTC
So what I am interested in is how do I implement a STUN/TURN server? (Would be great if someone could explain the differences in plain English!) And also is there a authentication mechanism. At the moment my app contacts my database and logins in user etc, but the stun and turn server would be private and not in any way involved in the authentication procedure.
So basically:
What is the best way to implement STUN/TURN
Is there any authentication mechanism?
Note, this is for a hybrid app so I will be using JavaScript/AngularJS for this. The main reason why I chose SimpleWebRTC.
Thank you!
I suggest you use an existing STUN or TURN server like coturn.
STUN servers are very lightweight and often left without authentication. A STUN server basically tells a client what its IP address appears to be, which is necessary to make peer connections across NAT (network address translation) boundaries.
TURN servers are very resource intensive because they relay media; all of the media for a call can go through the TURN server, so it's important to secure TURN. You use TURN servers in situations where UDP may be blocked, or for particular kinds of NATs that cause problems.
The authentication for coturn's TURN server can take one of two forms:
Simple (username, password) pair
TURN REST API. This uses a secret between the TURN server and another entity. The entity issues tokens with expiration times, and the TURN server verifies the token has not expired and was issued with knowledge of the shared secret. This is passed by the TURN client as a username, password pair in a format described in the documentation.

Any reason why latency in updating timelineitem to my glass device?

i see latency issue - when i send a timelineitem from my glassware app, it takes a long time to appear on glass device.
I see the item in developer playground (https://developers.google.com/glass/playground)
Is it isolated issue on my WiFi (unlikely)? or some optimization done at Mirror server which queues timelineitems and sending in a specific interval to glass device?
Thanks
After doing some more investigation (In my case, i have setup private network inside enterprise network), i found out that some of the ports are blocked by firewall settings for incoming traffic from outside network, so glass device was not getting notifications from the Mirror Server.
It is possible either Channel API or XMPP is used in receiving notification messages from Mirror server to Glass. Those ports might have blocked by my firewall settings. I ran wireshark, still it is not clear which protocol or port is used in receiving notifications.
Also it is possible that glass device could get (HTTP GET) newly available cards from the mirror server by polling on specific time interval or other cases(changing WIFI network, etc).
I called Glass help, i could not get any feedback.
I would really appreciate if someone (from Google) could shed some light (port and protocol details) on how Glass gets notification from mirror server when new timeline card is available.
This is a known issue:
https://code.google.com/p/google-glass-api/issues/detail?id=185
Issue has been fixed by updating to XE10.

What is the alternative way of sending user location via sms on iOS6?

i have done a security app which locate a iPhone and send the GPS location of the phone through message to an associated number this functions works good until iOS 5, but the issue is sending SMS without users knowledge is restricted in iOS 6, so i need a help here instead of sending message, is there any other possible way or replacement for this function? any answer related to this method are appreciated.
Thank you.
You haven't specified whether your ios app has a server. If yes, you can transmit location to server and that in turn can transmit it to intended user via specific api.
If this is not correct, APNS is your friend. This is a way to send messages to desired devices only, the ones who explicitly registers through your app.
Another quite equivalent option is to store it in public back-end like parse.com. As soon as other devices start your app, they can pull your location from there. If their device is already live, parse.com can make sure to notify them as soon as you change your location value in their DB.

Resources