Hi,
I would like to save files from my SD card on W5100 EthernetShield on Dropbox but I receive an error (see doc file) with HTTP request.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // BIA or Physical mac address of W5100 Shield
byte ip[] = { 192, 168, 1, 100 }; // IP ADDRESS of your device
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; // 24bit Subnet Mask
// Initialize Ethernet Client
EthernetClient client;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
startEthernet();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// DROPBOX
String PostData = "someDataToPost";
if (client.connect("content.dropboxapi.com", 80))
{
Serial.println("connected");
client.println("POST https://content.dropboxapi.com/2/files/upload");
client.println("Authorization: Bearer MY_TOKEN ");
client.println("Dropbox-API-Arg: {\"path\": \"/Matrices.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}");
client.println("Content-Type: application/octet-stream");
client.println("Host: content.dropboxapi.com");
client.println(PostData);
client.println("Connection: close");
client.println();
client.flush();
delay(5000);
Serial.println("Response from Dropbox API:");
while (client.available() != 0) {
Serial.print((char)client.read());
}
delay(1000);
client.stop();
}
else {
Serial.println("Couldn't connect to Dropbox API");
}
delay(1000);
}
void startEthernet()
{
Serial.println("Connecting to current network please wait...");
Serial.println();
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset the device and try again");
Serial.println();
}
else
{
Serial.println("Connected to network w/d DHCP");
Serial.println();
}
delay(1000); // Delay at 1 Seconds
}
Please can you advise me where is a problem?
Thank you very much,
Jan
Error.doc (24.5 KB)
Error.doc (24.5 KB)
Error.doc (24.5 KB)