Go Down

Topic: Send file from sd card to server (Read 5966 times) previous topic - next topic

Juraj

how large is the file? test with a small file.

hunter360

#16
Jul 06, 2018, 01:27 pm Last Edit: Jul 06, 2018, 01:27 pm by hunter360
 it it's small file.  Only create test 1 2 3 , and nothing else.

Juraj

#17
Jul 06, 2018, 02:05 pm Last Edit: Jul 06, 2018, 02:05 pm by Juraj
use IPAddress in connect and in Host header

Code: [Select]

IPAddress serverIP(123, 456, 78, 9);

if (client.connect(serverIP, 80)) {
...
client.print(F("Host: "));
client.println(serverIP);



hunter360


PieterP

Time to open up Wireshark then.

Juraj

#20
Jul 06, 2018, 06:16 pm Last Edit: Jul 06, 2018, 06:19 pm by Juraj
copy to Serial the response received by the client

Code: [Select]

  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.write(c);
    }
  }

hunter360



Code: [Select]
while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.write(c);
    }
  }

Nothing happened....

PaulS

Quote
Nothing happened....
Of course not. Your snippet won't even compile. If you want help, you'll stop posting snippets, and start posting ALL of your code.
The art of getting good answers lies in asking good questions.

hunter360

#23
Jul 10, 2018, 02:09 pm Last Edit: Jul 10, 2018, 02:18 pm by hunter360
Code: [Select]

  #include <ESP8266WiFi.h>
      #include <ESP8266WiFiMulti.h>
      #include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <SD.h>
 ESP8266WiFiMulti WiFiMulti;
File myFile;

void setup()
{

  Serial.begin(115200);

WiFiMulti.addAP("ssid", "password");
        WiFiMulti.addAP("ssid2", "password2");
     Serial.println("Connecting ...");
     

  int i = 0;
  (WiFiMulti.run() != WL_CONNECTED) ; // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
 delay(500);
 
   
   
   
      Serial.println('\n');
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());              // Tell us what network we're connected to
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
  while (!Serial) {
    ;
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");


  myFile = SD.open("test.txt", FILE_WRITE);

 
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
   
    myFile.close();
    Serial.println("done.");
  } else {
   
    Serial.println("error opening test.txt");
  }

  //
}

void loop()
{


IPAddress serverIP(00, 00, 000, 00);

WiFiClient client;
  if (client.connect(serverIP, 80)) {
   
while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.write(c);
    }
  }
 
    File myFile = SD.open("test.txt");
    client.println(F("POST /folder HTTP/1.1"));
    client.print(F("Host: "));
    client.println(serverIP);
    client.println(F("Connection: close"));
    client.print(F("Content-Length: "));
    client.println(myFile.size());
    client.println();

 
    while (myFile.available()) {
     
        client.write(myFile.read());
       
    }
    myFile.close();
    client.stop();
  }
 WiFiMulti.addAP("ssid", "password");
        WiFiMulti.addAP("ssid2", "password2");
     Serial.println("Connecting ...");
     

  int i = 0;
  (WiFiMulti.run() != WL_CONNECTED) ; // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
 delay(500);
 
   
   
   
      Serial.println('\n');
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());              // Tell us what network we're connected to
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
  while (!Serial) {
    ;
  }
}

Juraj

you should read the response after you send the request

hunter360

Code: [Select]
#include <ESP8266WiFi.h>
      #include <ESP8266WiFiMulti.h>
      #include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <SD.h>
 ESP8266WiFiMulti WiFiMulti;
File myFile;

void setup()
{

  Serial.begin(115200);

WiFiMulti.addAP("ssid", "password");
        WiFiMulti.addAP("ssid2", "password2");
     Serial.println("Connecting ...");
     

  int i = 0;
  (WiFiMulti.run() != WL_CONNECTED) ; // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
 delay(500);
 
   
   
   
      Serial.println('\n');
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());              // Tell us what network we're connected to
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
  while (!Serial) {
    ;
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");


  myFile = SD.open("test.txt", FILE_WRITE);

 
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
   
    myFile.close();
    Serial.println("done.");
  } else {
   
    Serial.println("error opening test.txt");
  }

  //
}

void loop()
{


IPAddress serverIP(00, 00, 000, 00);

WiFiClient client;
  if (client.connect(serverIP, 80)) {
   

 
    File myFile = SD.open("test.txt");
    client.println(F("POST /folder HTTP/1.1"));
    client.print(F("Host: "));
    client.println(serverIP);
    client.println(F("Connection: close"));
    client.print(F("Content-Length: "));
    client.println(myFile.size());
    client.println();

 
    while (myFile.available()) {
     
        client.write(myFile.read());
       
    }
    myFile.close();

while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.write(c);
    }
  }
    client.stop();
  }
 WiFiMulti.addAP("ssid", "password");
        WiFiMulti.addAP("ssid2", "password2");
     Serial.println("Connecting ...");
     

  int i = 0;
  (WiFiMulti.run() != WL_CONNECTED) ; // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
 delay(500);
 
   
   
   
      Serial.println('\n');
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());              // Tell us what network we're connected to
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
  while (!Serial) {
    ;
  }
}





still nothing

PaulS

That code looks like sh*t. Did you get a drunken monkey to operate the tab key for you?

Use Tools + Auto Format BEFORE you post crappy looking code like that again. Unless you don't want help. In which case, you are free to post crappy looking code.
The art of getting good answers lies in asking good questions.

Juraj

try it while connected to your wifi network. what is that wifimulti stuff?

hunter360


it was connected to wifi
wifimulti allowed me to set more wifi connections.



Juraj

it was connected to wifi
wifimulti allowed me to set more wifi connections.
but was it the same network where the server is?

Go Up