Skip to Content

Send IoT message via HTTPS to HCP by Python script

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?


Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Posted on Jan 24, 2017 at 04:56 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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. :-)

  • Posted on Jan 24, 2017 at 09:57 PM

    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:

    On certificate-based communication: or depending on whether it is a client or a server configuration.


    Add comment
    10|10000 characters needed characters exceeded