Hello,
I wanted to make a program that connects on the internet and opens some URLs. Those URLs are connected with webhooks and turns on or off some Sonoffs in my room. The thing is that I tried so many different ways to make it worked but it didn't. I thought that if I use an already made program that connects on a website and takes the webpage HTML source, but the programs I can find, uses this command to connect: "client.connect(host, 80)" and it means that the code connects with a port "80" and it doesn't work.
I want a program to connect on a direct website without the use of any port.
Thanks in advance for any kind of response!!
UKHeliBob:
Is port 80 not the standard HTTP port ?
Sorry, I didn't understand you.
But here is the full codes I tried to use (I removed my link from the code because maybe someone use it and turn my sonoffs on and off anytime he wants and I also removed the wifi password)
/*
This sketch establishes a TCP connection to a "quote of the day" service.
It sends a "hello" message, and then prints received data.
*/
#include <ESP8266WiFi.h>
#ifndef STASSID
#define STASSID "wifiname"
#define STAPSK "wifipass"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "google.com";
const uint16_t port = 17;
void setup() {
Serial.begin(115200);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
// This will send a string to the server
Serial.println("sending data to server");
if (client.connected()) {
client.println("hello from ESP8266");
}
// wait for data to be available
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
delay(60000);
return;
}
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("receiving from remote server");
// not testing 'client.connected()' since we do not need to send data here
while (client.available()) {
char ch = static_cast<char>(client.read());
Serial.print(ch);
}
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
delay(300000); // execute once every 5 minutes, don't flood remote service
}
I want a program to connect on a direct website without the use of any port.
a "client" connects to a device (e.g. PC) based on the IP address (or mac) and specifies a port to connect to a specific application on the device. A device can support 10000s of different types of applications
gcjr:
a "client" connects to a device (e.g. PC) based on the IP address (or mac) and specifies a port to connect to a specific application on the device. A device can support 10000s of different types of applications
the standard port # for a web server is 80.
I didn't know that!
Thanks.
So Im not searching for a client example to use!
I don't know but If I don't find any solution, I will make an Arduino Program and I will connect a lamp on my sonoff and make the Arduino try ALL the different ports and with a light sensor check if the lamp is off or not and it will save the port on an sd. So I will let the Arduino working for a night and the next morning probably I will have the webhooks port.