|
有加了,雖然還是不行,請問是寫法不對嗎
#include <SoftwareSerial.h>
#include <SD.h>
#define SD_CS 10
SoftwareSerial esp(4, 5); //RX,TX
String ssid = "6641k-16-14"; //wifi name
String password = "062643462"; //wifi password
String server = "120.114.132.69"; // server name
void connectWifi() //wificonnection
{
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if(esp.find("OK")){
Serial.println(F("WIFI Connected!"));
delay(1000);
}
else {
Serial.println(F("Cannot connect to wifi"));
connectWifi();
}
}
void wifisetup()
{
esp.println(F("AT"));
esp.println(F("AT+CWMODE=3"));
Serial.println(F("Wifi ready"));
}
void setup()
{
Serial.begin(9600);
esp.begin(9600);
pinMode(10, OUTPUT);
Serial.println(F("Wifi Setup"));
wifisetup(); //wifi setup
connectWifi();
Serial.print(F("Initializing SD card..."));
if (!SD.begin(SD_CS)) {
Serial.println(F("failed!"));
return;
}
Serial.println(F("OK!"));
test();
}
void loop() {
}
void test(){
File webFile;
char fileName[13] = "555.JPG";
String cmd = "AT+CIPSTART=\"TCP\",\"" + server + "\",80";
esp.println(cmd);
delay(3000);
if(esp.find("OK"))
{
Serial.println(F("server found"));
webFile = SD.open(fileName,FILE_READ);
Serial.print(webFile);
String post = F("POST /skin/upok.php HTTP/1.1\r\n");
post += F("Host: 120.114.132.69\r\nContent-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWxkTrZu0gW\r\n");
post += F("Content-Length:");
post += webFile.size()+196;
post += F( "\r\n");
post += F("----WebKitFormBoundary7MA4YWxkTrZu0gW");
post += F("Content-Disposition: form-data");
post += F("name=\"my_file\"; filename=\"555.JPG\"\r\n");
post += F("Content-Type: image/jpeg\r\n");
post += F("----WebKitFormBoundary7MA4YWxkTrZu0gW--\r\n");
delay(1000);
Serial.print(post);
String sendData = "AT+CIPSEND=" + String(post.length());
Serial.println(sendData);
esp.println(sendData);
delay(6000);
if (esp.find(">"))
{
Serial.println(F("SENDING data"));
}
else
{
Serial.println(F("NOT SENDING"));
esp.println(F("AT+CIPCLOSE"));
}
}
else
{
Serial.println(F("server not found"));
}
delay(10000);
}
|
|