Send REST API requests through Azure IoT Hub to a Raspberry Pi webserver - azure

I'll start off by apologizing if this has been asked and answered, but I've been researching this for a few days and either I'm not understanding what I'm reading or I'm trying to do something unique or not possible(guessing it's the former).
Currently what I have is a Raspberry Pi that has a webserver running and a web UI for controlling what's connected to it. It has a slew of REST API's that can be accessed to perform various tasks. I have a couple of these setup with static IP addresses and all works great. My problem is scale. The potential exists to have hundreds(to thousands) of these running and need to be controlled by a single mobile app. I don't want to have thousands of static IP's. Though this would be the easiest solution it certainly wouldn't be cost effective and most likely a nightmare to manage.
My desire is to "connect" all of these Raspberry Pi webservers to the Azure IoT hub. The webservers do not need to talk to each other, but the mobile app needs to be able to send REST messages to each server individually.
The coding of the app, the coding on the Pi's and any additional coding is not an issue. I've been an applications developer for over 20 years so coding is not an issue.
So, my questions are:
What is the minimum necessary to be running on the Pi to connect to the Azure IoT Hub?
Do I understand correctly that to do what I've described above, I have to send a message to the Hub and then the Hub sends a message to the device?
Does anything exist to define the Pi as an endpoint and just be able to send the REST messages directly to that?
Any help provided, even links to relevant documents, would be greatly appreciated. Thank you!

Have you checked the official documentation? It contains an example of what you're trying to achieve (send data from device to iot hub / send command from iot hub to device)
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-c2d
All you need is the connection string to the Azure IOT Hub. To register your device, please visit: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-sdks

Related

Can I connect via Bluetooth(or USB) to a device sitting locally at my desk from the App running on Test-Cloud?

I work with POS devices. We have a cross-platform mobile Xamarin App which talks to POS devices using Bluetooth or USB.It would be a great help if you can do that.
No you cannot, unfortunately the only way to interact with any device needed by the mobile client is through web requests. Unfortunately this is limited because no 1 BLE solution would work for everyone (actually it would only work for very few).
Another challenge is that the automated UI tests will run in the order determined by Xamarin Test Cloud and you may potentially have multiple devices interacting with your one device.
You could do this all locally though on your own device. You would just trigger the UITest locally through the command line and have the BLE device by your phone. I know this isn't ideal, but really one of your best options here.
The other option you have is creating a middle-man for your POS devices. Basically the middleman would be a REST API hosted on some IoT device that contains BLE integration. You would than have to forward the BLE requests from the IoT device to your POS device, but this solution would require larger time frames for the data to transfer and wouldn't necessarily be a "real-world" testing scenario. I would expect that you would have some false failure tests due to the details with creating this solution. I have done something similar for Particle, but I was only able to run UI Tests on 1 device at a time.
Disclosure: I work for Xamarin/Microsoft.

Azure Event Hubs C Client

I am trying to send messages to Azure Event Hubs from an Arduino with a Wifi extension. Is there a way to upload the data without using the provided libraries?
You will need some kind of device to act as a gateway. The Adruino board cannot provide this functionality. Most likely, you will need to connect the device to a Raspberry Pi and send the messages using the Pi. Below is directions and code on how to set this up.
https://github.com/MSOpenTech/connectthedots

how does an app detect device on network

I use apps that interact with their specific devices. An example is Roku. The device is Roku and I use their Android App. Another is my Denon Audio receiver and it too has an app to control it. I'm looking to write app/hardware service. how does an app detect device on network and vice-versa?
Disclaimer: I don't know what Roku is but what you are describing sounds like service discovery as part of zeroconf.
One relatively known example is DNS-SD. You can think of it as sending periodically multicast UDP messages containing stuff such as "I am at address X and I provide service Y" to some well-known address. Whoever is interested will pick up the information associated.

Is it possible to make a Chromecast device discoverable to devices that are not whitelisted?

For example, if I have a friend over and he wants to show me a video using a given app that runs both on my device and his device. Could that app display a QR code on the screen or something that he could scan and instantly be granted access to my Chromecast device?
As Ali mentioned, Chromecast devices are discovered and apps launched via local network applications. One an app is started, it could easily connect with a cloud service that allows other (non-local) devices to talk w/ your Chromecast via the cloud service. A Chromecast Receiver application is just a HTML5 application (HTML, CSS, and JavaScript). You can really do what ever you want once your application gets launched.
If displaying a QR code that allows some kind of rendezvous with your cloud application is what you want to do, you can certainly do that.
I presume your friend's mobile device is on the same wifi network, right? Currently, a chromecast device has no identity outside of its local wifi network, so if the sender is not on the same network as the receiver, there is no way they can exchange messages. Back to your question, if your friend is on your network, then he could see your device except from those applications for which your device is not whitelisted for. Is that the case you want to handle through, say, a QR code? If so, that is currently not doable either since whitelisting is not just a local setup. Maybe I misunderstood your question?
Based on your questions, you are saying that both you and your friend have the same app. If so, and if your friend connects to your wifi network, then he will see your chromecast (you do not whitelist a device for a phone, you whitelist a device for an app id and as long as your friend has the same app (hence the same app id I resume), your whitelisted device will be discoverable by his phone. On the other hand, if you do not want to give him credentials to get on your network, then you need a cloud backend and a lot of work, since although your chromecast device can send a message to cloud and your cloud service can notify the other user's phone (using, say notification or some other mechanism that you employ in your app), the reverse (i.e. sending a message from your friend's phone to your chromecast (through your cloud service)) is much harder. Your friend's phone can send your phone a message (again via a back end service, a bluetooth communication, NFC, etc and then your phone using your app can send that to the chromecast receiver but I am sure you are getting the idea that it is a lot of work. Signing up on your wifi network can be made easier with a QR code or something so at this pint, that would be the easiest solution.

nodejs IoT device to device communication

so im working on a my bachelor thesis and for that i need to implement, in a smarthome, d2d communication between IoT devices. So i want to implement the usuall server work, like noticing if a device connects/ disconnects etc. to the IoT devices, so no server/hub is needed at home.
But I can't find good solutions for it, for websockets i need a server, for mqtt a broker and so on, but all need a server.
I found that d2d is done with "LTE" similar technology but i would like to do it with web-protocols.
So my question:
Is there a way to let IoT devices talk to each other over the network?
My IoT devices (raspberry pis) currently use nodejs with typescript but I'm not starting a server, they only have a mqtt connection to publish there sensor data to the users.
Thanks in advance.
And if im understanding something wrong, please say it. :)

Resources