Example of downloading JSON over SSL?

Does anyone have working code that downloads a text file over SSL and then parses it?

The SSL libraries I’ve found don’t seem to do anything with the response content, or otherwise seem incomplete.

This is a great webhook parser that's built to be memory efficient.

I figured out how to use it in this thread which may or may not be helpful.

1 Like

@RWB I’m not sure I follow. Is that the right thread? It has to do with storing data to be published later. I am in need to downloading data over SSL.

My Bad, it was the wrong link. I updated the link above.

Not sure if it could help you since it’s parsing incoming webhooks but figured it was worth a shot since it’s a parsing program and figured maybe you can get your data back via a webhook or in JSON format.

Thanks for the quick reply!

Unfortunately, parsing JSON is the easy part :smiley:. It’s downloading the data over from an HTTPS site that’s holding me back at the moment.

Have you considered webhooks?

Webhooks for what? I need to periodically pull from a passive data source.

So what do you have working now?

Everything else?

I want to read some JSON from an HTTPS site. That I am having trouble with.

Once I’ve read it, parsing it, interpreting it, reacting to it, etc, is all covered.

I think webhooks would be the way to go.

Webhooks involve the other party pushing data to me. That is not an option.

I need to pull the data from the other party.

So you can pull the JSON into the Photon/Electron successfully, right?

No. That is what I am asking. How do I connect to an HTTPS site and download the file.

Can you post a screenshot of the data the HTTPS site returns from your request?

Hi @mankyd

I think the thing you are missing is that a webhook can be triggered by a publish from your device and cause the Particle cloud to do some thing to another web server and then return the response from the other web server to your device.

In your case, it sounds like you do not want to POST any data from a device, just GET data back to a device, but that is very possible including template matching the response from the other web server to get less data, since that is often required.

4 Likes

@bko Ah, you mean something like this? https://docs.particle.io/guide/tools-and-features/webhooks/#getting-the-response

Just so I’m clear:

  1. I publish an even to the remote url. The contents of the publish are irrelevant, since the file I am downloading doesn’t care.
  2. Particle calls back at hook-response/[...] and I can then parse the response.

Effectively, Particle’s cloud services are acting as a proxy?

p.s. The returned JSON should be relatively small (a few hundred bytes tops).

Yes, that is about it. You just have to setup the webhook the way you need to hit the other web server correctly.

And then you can follow this thread and use Ricks JSON Parsing library and tools to efficiently setup and parse the response that's coming back.

His library is for sure the way to go for parsing incoming JSON from Webhooks. I tried others way before, and they were less than ideal and used up more memory and Strings that can cause lockups.

1 Like

To be more exact, you push the event to the Particle Cloud Webhook, the webhook is setup to forward the request of your choice (GET, POST, PUT, ... - with or without data contained in the triggering event) to the respective URL and waits for the response in order to relay it back to your device.

3 Likes

It also eliminates the need for the HTTS library since the Particle Webhook integrating handles the HTTPS request in the cloud. This, of course, frees up memory space on your device for other uses.