Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create dataPublisher for Azure Event Hub REST API #411

Open
aufdenkampe opened this issue Apr 14, 2022 · 4 comments
Open

Create dataPublisher for Azure Event Hub REST API #411

aufdenkampe opened this issue Apr 14, 2022 · 4 comments
Assignees

Comments

@aufdenkampe
Copy link
Member

aufdenkampe commented Apr 14, 2022

Add support for streaming data to a Microsoft Azure EventHub service REST API endpoint with authentication via a Shared Access Signature (SAS) token.

Documentation for Event Hubs service REST:

A example POST request looks like this:

POST https://your-namespace.servicebus.windows.net/your-event-hub/messages?timeout=60&api-version=2014-01 HTTP/1.1  
Authorization: SharedAccessSignature sr=your-namespace.servicebus.windows.net&sig=tYu8qdH563Pc96Lky0SFs5PhbGnljF7mLYQwCZmk9M0%3d&se=1403736877&skn=RootManageSharedAccessKey  
Content-Type: application/atom+xml;type=entry;charset=utf-8  
Host: your-namespace.servicebus.windows.net  

{ "DeviceId":"dev-01", "Temperature":"37.0" }

The key innovation here is to write a SAS signature, for which we first need to complete:

Generate a Shared Access Signature (SAS) for Azure Event Hub

SAS Format:

SharedAccessSignature sig=<signature-string>&se=<expiry>&skn=<keyName>&sr=<URL-encoded-resourceURI>

Where:

  • sig - URL-encoded HMACSHA256 signature.
    • The hash computation looks similar to the following pseudo code and returns base64 of raw binary output.
    • urlencode(base64(hmacsha256(urlencode('https://<yournamespace>.servicebus.windows.net/') + "\n" + '<expiry instant>', '<signing key>')))
  • se - Token expiry instant. Integer reflecting seconds since the epoch 00:00:00 UTC on 1 January 1970 (UNIX epoch) when the token expires.
  • skn - Name of the authorization rule.
  • sr - URL-encoded URI of the resource being accessed.
@aufdenkampe aufdenkampe self-assigned this Apr 14, 2022
@aufdenkampe aufdenkampe changed the title Create dataPublisher for Azure Service Bus Messaging Create dataPublisher for Azure Event Hub Apr 15, 2022
@aufdenkampe aufdenkampe changed the title Create dataPublisher for Azure Event Hub Create dataPublisher for Azure Event Hub REST API Apr 15, 2022
@aufdenkampe
Copy link
Member Author

@SRGDamia1, I'm having a bunch of trouble getting this to work with the new EnviroDIY LTEBee (SIM7080), and I need your help.

The short story is that although I'm able to connect to the server and send a properly formatted POST Request (that works in Postman), on the Mayfly + SIM7080 modem, the data aren't going through and I'm not getting any response from the server.

Note that this uses HTTPS via port 443, which this modem seems to support. By specifying that port, I was able to get a connection to the endpoint server (but no connection with Port 80), so I think I'm OK on that.

To troubleshoot and solve this, I think I need to dive in to deeper use of the TinyGSM library functions, but I'm really new to that library and it's functions.

Can you offer suggestions?

aufdenkampe added a commit that referenced this issue Apr 19, 2022
@GArrigotti-cws, @GArrigotti, I also added `platformio.ini` files that you can use for testing on your side.

Connected to #411
@aufdenkampe
Copy link
Member Author

@GArrigotti-cws, @GArrigotti, with the last commit 4b624c7, I also tested on a Digi radio and got the same result: no response from the server, even when the entire request is identical to the raw request that works in Postman.

In that last commit I included platformio.ini files that would allow you to test my two sketches (one for each radio) yourself.

@aufdenkampe
Copy link
Member Author

aufdenkampe commented May 3, 2022

In commit 8bc473c from work done on 4/20/22, I figured out the main issue here.

The key was to use TinyGsmClientSecure rather than TinyGsmClient in src/modems/SIMComSIM7080.h.

This fully enabled HTTPS. It turns out that specifying Port 443 in src/publishers/EventHubPublisher.cpp (rather than Port 80 which is used for HTTP) was not sufficient.

@SRGDamia1, let's connect to discuss ideas on how to best implement HTTPS across all modems and publishers in ModularSensors.

For example, it would be ideal to start migrating to HTTPS for new EnviroDIY stations posting to MonitorMyWatershed.org

@aufdenkampe
Copy link
Member Author

@SRGDamia1, I would like to pick up this conversation about how to best architect the modems and publishers code to for a user to easily switch between HTTP and HTTPS.

As I mentioned above in #411 (comment), depending on the Publisher's endpoint, we need to instantiate the gsmClient within the Modem either using TinyGsmClient (as currently done for HTTP) or using TinyGsmClientSecure (for HTTPS).

I got this working, but only for src/publishers/EventHubPublisher.cpp.

That work is presently all in the hmac_auth branch.

I'll look at it more closely in the coming week or two and set up a time to discuss options with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant