I have tried to make for ESP8266 a simple FTP client program for some time, no success.
I want to send light value, time + lux=max 65535, to my internet home page. A simple data. How I get time from the internet? This is a second problem.
I can send a data to such Internet place, which doesn't require password, but my internet place requires it.
I use ESP8266 for the reason I can put it outside the house, and use light power, which charge LiOn battery, two 18650 batteries in parallel. I will send it at daytime in hours interval. There is other program, which takes the data and converts to continuous data file. Then it will go to PC graphics. These other things has worked about 15-20 years, but I am quite new in esp8266.
I found from Internet this program. It works, but I need also a password to my Internet service. Can somebody help me?
#include <ESP8266WiFi.h>
// SSID
const char* ssid = "MyWifiid";
const char* password = "MyWifiPassword";
// Host
const char* host = "dweet.io";
void setup() {
// Serial
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
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() {
delay(5000);
Serial.print("connecting to ");
Serial.println(host);
//Connect to the host server:
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
//Formulate the URI for the GET request we will send to the host server:
// We now create a URI for the request
String url = "/dweet/for/MyLight?Lux=65535";
//Send the GET request to the server and check whether the request has been received or if it has timed out:
// Send request
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
//Read incoming data from the host server line by line and display the data on the serial monitor.
//Close the connection after all the data has been received from the server:
// Read all the lines from the answer
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
// Close connecting
Serial.println();
Serial.println("closing connection");
}