ModuleClient IoT Hub Edge device: How to receive messages from device queue? - iot

We deploy IoT Edge Modules to our devices and can send messages to IoT Hub or execute direct methods. ModuleClient however also has a few methods (such as CompleteAsync) to delete a message from the device queue.
Q: Is there any way to receive device queue messages directly in the module? Either by routing rules, use of a ModuleClient method or possibly even by using a DeviceClient instance within a Module?
Any help would be much appreciated.

Not really. Only direct methods are supported with IoT Edge modules. there is sort of a workaround but I would actually not recommend exposing config.yaml to a module.

Related

Sending MQTT commands with QOS1 via GCP Cloud IOT

We are currently trying to communicate with Edge devices using MQTT. We use the config topic for defining the algorithms to use, the version of software and so on.
We would like to use commands for sending "calculation results" back to the devices. We have to send it from the cloud towards the devices since multiple devices are working together on this.
This state is important for the device to visualise the correct state and therefor we would like to have QOS1 for these commands.
According to the documentation this should be possible but I can't find out how to do this.
We are using the API's for managing these config and commands.

How to manage multiple IoT Agents in Fiware

I have two type of devices one support IoT JSON agent and another Ultralight Iot Agent. What approach is best should i used both IoT agent separately or there is something like IoT manager. What in future i have another device which support another IoT Agent like LoRaWan .
I have tried IoT manager but could not understand it is only for device provisioning or actual device data transfer also.
IoT Manager acts as a proxy for actual IOTAs, so depending on some parameters in the request (I don't remember exactly which ones, but they should be described in the IOTAs documentation) redirects the request to one or another IOTA agent.
But of course, you can implement this proxy using another piece of software (e.g. ngix with some king of URL-based or port-based redirection) if you want.

How to get a list of IP of all devices on the LAN?

We used the library SimplePing, but multiple challenges of our network scanner sometimes some devices were not found. ie This scanner does not work reliably.
Prompt another library or a more reliable algorithm for IOS?
Perhaps I need to write a ping using sockets:
socket(AF_INET,SOCK_DGRAM,IPPROTO_ICMP)
But what further code?
You can see the implementation of ping utility in FreeBSD source code: https://svnweb.freebsd.org/base/release/10.1.0/sbin/ping/ping.c?view=markup
Don't be afraid to read source codes of existing implementations for any platforms, because they all use the same basis, and your app will not be an exception.
Btw, you can compile C-code for your app written in Objective-C.
Update.
And here is a good explanation about how to use sockets: http://www.linuxhowtos.org/C_C++/socket.htm
Not all devices respond to ICMP PING (which is what you're using). Are there specific devices that are never discovered? If so, do they respond to the "ping" command?
If it is more erratic, then you need to start with network traces (most commonly using wireshark). You need to determine if the pinged machine received the ping, and separately whether your device received the response. You will generally want to build a small, private network for this so you can control the hardware.
Generally speaking, it is easier to initially develop this kind of code in the simulator rather than a device. Does it work more reliably in the simulator?
Are you receiving errors? Are there firewalls involved? (Firewalls often swallow ICMP without generating errors.)
You're going to need a lot more specific diagnostic information beyond "does not work reliably." You need to know exactly which pieces do and don't work. Did you send the packet? Did they receive the packet? Did they send the response? Did you receive the response? Without those basic data, it's very hard to troubleshoot networking.

Azure IoT Communication

I have an embedded device that can be controlled by JSON over UDP. I am currently performing this via an iOS App, and everything works great.
I am now wanting to be able to also control my device from a remote location. And am wanting to use Azure to perform this task. I envision that I will set up an Azure Website which will enable me to select options which then send the JSON to my device, which is behind a firewall.
My question is which of the Azure Services should I be looking into? Also, what is the best way to get the JSON packet to the device behind the firewall (I do not want to use port forwarding).
In general, to avoid an attack surface from outside your LAN (where you have your embedded device), the better solution is to open and output connection from embedded device to the cloud and to leave it open so that it can send and receive data/command.
In this case, on Azure you can use the Service Bus (queue, topic/subscription or event hub) to send/receive with AMQP protocol but it is strictly related to your device and capabilities.
Can you share more information on it ? How much it is a constrained device or a more power device with an high level OS (Linux, Windows, ...) ?
Paolo Patierno
About using Amqp on devices running android is very tedious. The java implementation in dalvik is missing a lot of required apis to be there.
By the way, do you know where we can find information about related path segments to use in amqp pure syntax in Azure, to interact with IoT-Hub end-points. Like for queue for example, we can have :
amqps://:#.servicebus.windows.net/
Thanks

Communication architecture choice in an IOS / Linux application?

I have a software architecture problem.
I have to design an IOS application which will communicate with a Linux application to get the state of a sensor, and to publish an actuator command. The two applications run in a Local network with an Ad-Hoc WiFi connection between the IOS device and the Linux computer.
So I have to synchronize two values between two applications (as described in figure 1). In a Linux/Linux system, I resolve this kind of problem thanks to any publisher / subscriber middleware. But how can I solve this problem in an IOS / Linux world ?
Actually the Linux application embed an asynchronous TCP Server, and the IOS application is an asynchronous TCP client. Both applications communicate through the TCP Socket. I think that this method is a low level method, and I would like to migrate the communication layer to a much higher level Service based communication framework.
After some bibliographic research I found three ways to resolve my problem :
The REST Way :
I can create a RESTful Web Service which modelize the sensor state, and which is able to send command to the actuator. An implementation of a RESTful web service client exists for IOS, that is "RESTKit", and I think I can use Apache/Axis2 on the server side.
The RPC Way :
I can create on my Linux computer a RPC service provider thanks to the libmaia. On the IOS side, I can use xmlrpc (https://github.com/eczarny/xmlrpc). My two programs will communicate thanks to the service described in the figure below.
The ZeroConf way :
I didn't get into detail of this methods, but I suppose I can use Bonjour on the IOS side, and AVAHI on the linux side. And then create custom service like in RPC on both side.
Discussion about these methods :
The REST way doesn't seem to be the good way because : "The REST interface is designed to be efficient for large-grain hypermedia data transfer" (from the Chapter 5 of the Fielding dissertation). My data are very fined grain data, because my command is just a float, and my sensor state too.
I think there is no big difference between the ZeroConf way and the RPC Way. ZeroConf provide "only" the service discovering mechanism, and I don't need this kind of mechanism because my application is a rigid application. Both sides knows which services exists.
So my question are :
Does XML RPC based method are the good choice to solve my problem of variable synchronization between an iPhone and a Computer ?
Does it exist other methods ?
I actually recommend you use "tcp socket + protobuf" for your application.
Socket is very efficient in pushing messages to your ios app and protobuf can save your time to deliver a message instead of character bytes. Your other high level proposal actually introduces more complications...
I can provide no answers; just some things to consider in no particular order.
I am also assuming that your model is that the iOS device polls the server to synchronize state.
It is probably best to stay away from directly using Berkeley sockets on the iOS device. iOS used to have issues with low level sockets not connecting after a period of inactivity. At the very least I would use NSStream or CFStream objects for transport or, if possible, I'd use NSURL, NSURLConnection, NSURLRequest. NSURLConnection's asynchronous data loading capability fits well with iOS' gui update loop.
I think you will have to implement some form of data definition language independent of your implementation method (RES, XML RPC, CORBA, roll your own, etc.)
The data you send and receive over the wire would probably be XML or JSON. If you use XML you would have to write your own XML document handler as iOS implements the NSXMLParser class but not the NSXMLDocument class. I would refer JSON as the JSON parser will return an NSArray or NSDictionary hierarchy of NSObjects containing the unserialized data.
I have worked on a GSOAP implementation that used CFStreams for transport. Each request and response was handled by a request specific class to create request specific objects. Each new request required a new class definition for the returned data. Interactivity was maintained by firing the requests through an NSOperationQueue. Lots of shim here. The primary advantage of this method was that the interface was defined in a wsdl schema (all requests, responses, and data structures were defined in one place.
I have not looked at CORBA on iOS - you would have to tie in C++ libraries to your code and change the transport to use CFStreams Again, lots of shim but the advantage of having the protocol defined in the idl file. Also you would have a single connection to the server instead of making and breaking TCP connections for each request.
My $.02
XML RPC and what you refer to as "RESTful Web Service" will both get the job done. If you can use JSON instead of XML as the payload format, that would simplify things somewhat on the iOS side.
Zeroconf (aka bonjour) can be used in combination with either approach. In your case it would allow the client to locate the server dynamically, as an alternative to hard-coding an URL or other address in the client. Zeroconf doesn't play any role in actual application-level data transfer.
You probably want to avoid having the linux app call the iOS app, since that will complicate the iOS app a lot, plus it will be hard on the battery.
You seem to have cherry picked some existing technologies and seem to be trying to make them fit the problem.
I would like to migrate the communication layer to a much higher level Service based communication framework
Why?
You should be seeking the method which meets your requirements in terms of available resources (should you assume that the client can maintain a consistent connection? how secure does it need to be?) However besides functionality, availability and security, the biggest concern should be how to implement this with the least amount of effort.
I'd be leaning towards the REST aproach because:
I do a lot of web development so that's where my skills lie
it has minimal dependencies
there is well supported code implementing the protocol stack at both ends
it's trivial to replace either end of the connection to test out the implementation
it's trivial to monitor the communications (if they're not encrypted) to test the implementaiton
adding encryption / authentication does not change the data exchange
Regards your citation, no HTTP is probably not the most sensible for SCADA - but then neither is iOS.

Resources