Go Down

Topic: how to send a html request using an Arduino? (Read 232 times) previous topic - next topic

JakobKrause

Hi,
I am currently using an arduino connected to the internet to control it remotely and now i want to trigger it from a different arduino, simply by calling "http://139.59.206.133/xxxxxxxxxxxxxxxxx/update/V34?value=1".
When I type this into my browser it changes the value on the arduino i want to control.
But now I want to trigger this by pressing a button on a different arduino. Till now i found no way to call this html adress.
Can you help me, please  :)

Juraj

#1
Aug 09, 2018, 09:36 pm Last Edit: Aug 09, 2018, 09:36 pm by Juraj
see the WebClient example
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

JakobKrause

#2
Aug 09, 2018, 09:45 pm Last Edit: Aug 09, 2018, 09:48 pm by JakobKrause
I have already tried so many things with client.connect and those things but none worked

JakobKrause

#3
Aug 09, 2018, 10:05 pm Last Edit: Aug 09, 2018, 10:11 pm by JakobKrause
I can actually connect to a page like www.google.com but the one that I want does not work. :(
For instance www.google.com/maps doens't work either. Not even www.google.com/
Does anyone has an idea to make different clients possible?

Juraj

I saw a nice answer today. The problem is on line XX. You used XXXXXXX instead of XXXXXX.
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

JakobKrause

#5
Aug 09, 2018, 10:16 pm Last Edit: Aug 09, 2018, 10:17 pm by JakobKrause
well I used the XXXXXX to censor a sensitive information :D

Juraj

Sorry. I meant "The problem is in your code at line XX. You used XXXXXXX instead of XXXXXX."
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

JakobKrause


Juraj

You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

JakobKrause

/*

 This example connects to an unencrypted WiFi network.
 Then it prints the  MAC address of the WiFi shield,
 the IP address obtained, and other network details.

 Circuit:
 * WiFi shield attached

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 */
#include <SPI.h>
#include <WiFi101.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the WiFi radio's status
WiFiClient client;
char server [] = "www.google.com/maps";

// when you use this server it won't connect but with www.google.com it will


void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ;
  }


  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);


    delay(10000);
  }


  Serial.print("You're connected to the network");


}

void loop() {
 
if (client.connect(server, 80))
    Serial.println("connected");
  delay(10000);
 
}









Juraj

#10
Aug 10, 2018, 06:51 am Last Edit: Aug 10, 2018, 06:51 am by Juraj
I can actually connect to a page like www.google.com but the one that I want does not work. :(
For instance www.google.com/maps doens't work either. Not even www.google.com/
Does anyone has an idea to make different clients possible?
you can't add path to variable 'server;. it is hostname that will be resolved to IP address at connect(). the url goes to first line sent to server. the HTTP protocol determines it. it is "GET /requested/url HTTP/1.1". and then the Host header is mandatory on next line.

look better at the WebClient example
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

JakobKrause

#11
Aug 10, 2018, 12:20 pm Last Edit: Aug 10, 2018, 12:41 pm by JakobKrause
Thanks so far.

I have edited my code but i still does not work.

Do you find any misktakes? :)

/*

 This example connects to an unencrypted WiFi network.
 Then it prints the  MAC address of the WiFi shield,
 the IP address obtained, and other network details.

 Circuit:
 * WiFi shield attached

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 */
#include <SPI.h>
#include <WiFi101.h>

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = "";        // your network SSID (name)
char pass[] = "";    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the WiFi radio's status
WiFiClient client;
char server [] = "139.59.206.133";



void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ;
  }


  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);


    delay(10000);
  }


  Serial.print("You're connected to the network");


}

void loop() {
 
if (client.connect(server, 80))
    Serial.println("connected");
    client.println("GET /a166e9xxxxxxxxxxxxxxxxxx60e264/update/V34?value=1 HTTP/1.1");
    client.println("Host: 139.59.206.133");
    client.println("Connection: close");
    client.println();
    client.stop();

  delay(10000);
 
}

JakobKrause

Nevermind I just managed it.

Thank you very much :D
Have a nice day

Loeksr

Hi Jakob,

Was reading this item top to bottom and I would now really like to know HOW you managed it!

Could you please post the code that actually did work?

Thanks,
Loek

JakobKrause

The last code, that I posted was actually working. I just messed up the authentication code.

Go Up