Electron as web client

I how not been able to figure out how I can use Electron as a web client. For example I would like to go to a page a post data like this:

http://www.mysite.com/data.aspx?field1=value1

How can I do that?

What do you mean with “web client” exactly?

But for what you asked to do there will be best done via this
https://docs.particle.io/reference/javascript

Having a look in the docs before posting a question is much appreciated (a.k.a. not so frowned upon than the other way round).

Thank you for your answer, I’m sorry, please bear with me. A part of being a beginner is to learn how to navigate documentation. And ask lots of “wrong” questions. Eventually I will be able to ask better questions (and possible even to contribute). And buy more Electrons! :wink:

This is what I would like to do: I want the Electron to take temperature measurements at regular intervals. I know how to do that. Then I want the Electron to post each value to a web page (that I create and host on my own server). It’s easy to create the string (http://www.mysite.com/data.aspx?field1=value1) but how do I make a call to this URL using Electron?

I have already been able to do what I want using an Arduino and an Arduino Ethernet Shield. It works well, but it’s a wired solution. Now I want to do the same over GSM.

Thanks for pointing me in the right direction!

Other keywords to look up in the docs for what you said there might be Particle.publish() which would be one way to actively push data from your device.
In conjunction with this Webhooks would be useful.
And less secure (but since your page is not https but http) you could look at TCPClient or even the HTTPClient library


I’d go for Particle.publish() and webhooks, since this is secure and uses little of your data allowance.

1 Like

Yes, I was able to make it work! Here’s the Electron code:

TCPClient client;

void setup() {
 
Serial1.begin(9600);
Serial1.println("Connecting...");

if (client.connect("mysite.com", 80))
{
    Serial1.println("Connected");
    client.println("GET /?temp=89 HTTP/1.0"); //the measured temp is 89 deg
    client.println("Host: mysite.com");
    client.println("Content-Length: 0");
    client.println();
    Serial1.println("Temp transmitted");
}
else
{
    Serial1.println("connection failed");
}
}

At the server I run an ASP.NET script that captures the temperature when the page loads (in this case with ‘mysite.com?temp=89’).

Request.QueryString("temp")

The rest of the ASP.NET script stores the data.

2 Likes

That’s awesome! Congratulations! Seems as though you are quickly on your way to graduate from “beginner-hood” :slight_smile:

Let us know if there’s anything we can do to help you continue the journey!

1 Like