Skip to Content
1

Send IoT message via HTTPS to HCP by Python script

Jan 24, 2017 at 03:37 PM

338

avatar image

Hi together,

I have a Raspberry Pi which collects data with some sensors. Now I want to post these sensor data via HTTPS request to HCP. But how?

I tried using a Python script from the iot-starterkit but there I would have to use a certificate but my HCP trail account doesn't support certificates. Now I got the information that it should also be possible to authenticate my Raspberry Pi via the OAuth access token. How can I achieve that? How do I have to use Certifi correctly?

BR
Simon

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Anton Levin
Jan 24, 2017 at 04:56 PM
1

Hello Simon, in the example you have referenced, "certifi" python package is used for validation when building the http connection (you just install it with pip). But you authenticate your call with OAuth (see line #25). That bearer token you get when you register your device in IoT Cockpit. So, that example is exactly what you need - it sends your sensor data to HCP over HTTPS. Regards, Anton

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Hi Anton, thanks for your answer! OK, but what do I have to do with the code from line 12 to 15? Can I just delete this from my Python script? BR, Simon

0

No, why would you do that? It creates "http" object which is used then in line #41 to fire the HTTP POST request.

0

Because there the script wants to have a certificate bundle. But I don't have a certificate and according to my information my trial account doesn't support certificates. So what do I have to configure in line 14?

0

To make that example run, you have to adapt the next lines only:

#16 - uncomment if you are behind a proxy and set your proxy

#19 - give your actual URL to iotmms

#25 - give your device token

#29 - adapt message type id and payload

Of course, you might want to work without certifi -> just leave "http = urllib3.PoolManager()" with no arguments but this will cause "urllib3" throwing "insecure request warnings" and increase a chance of the MITM attacks

0

This seemed to help. Connection is now established, anyway I get error code 400 from the server. Maybe my string is not correct. But this I'll post in another question if I don't find the error. Thanks for help with HTTPs problem. :-)

0
Moya Watson
Jan 24, 2017 at 09:57 PM
0

Hi Simon! thanks for writing the question. In addition to what Anton said here, my colleagues suggested you have a look at these references:

Documentation on connectivity services of HCP:

https://help.hana.ondemand.com/help/e54cc8fbbb571014beb5caaf6aa31280.html

On certificate-based communication:

https://help.hana.ondemand.com/help/frameset.htm?3f1247537c1a4f069235ee63633659c5.html or https://help.hana.ondemand.com/help/frameset.htm?9018a9e54b3c48d98aa63538d47bdcd6.html depending on whether it is a client or a server configuration.

thanks!

Share
10 |10000 characters needed characters left characters exceeded