je souhaite enregistrer des événements dans une page google sheet. Je n'arrive pas à ouvrir la connection (Carte Méga + sheild W5500). connection filaire
ne rentre pas dans : if (client.connected())
voici mon code :
#include <Ethernet.h> // librairie pour la carte ethernet
#include <EthernetUdp.h> // librairie pour la gestion UDP
#include <SPI.h> // librairie pour la communication avec la carte ethernet
//#include <DS3231.h>
//#include <Wire.h>
char formkey[] = "xxxxxxxxxxxxx"; //Replace with my Key
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAB }; // mac de l'arduino, à modifier voir sur la carte ethernet
byte ip[] = { 192, 168, 1, 31}; // ip fixe de l'arduino à choisir
EthernetServer serverHTTP = EthernetServer(80);
EthernetServer server(80);
EthernetClient client;
byte ArduinoMAC[] = { 0xDE, 0xEF, 0x14, 0x05, 0xFE, 0xAB };
static IPAddress ArduinoIPAddress(192, 168, 1, 31);
unsigned long compteur1000ms; //Compteur pour interruption
unsigned long compteur200ms; //Compteur pour interruption
String data;
#define SERIAL 1 // 1 pour activer trace sur port série, 0 pour la désactiver
// ********************** debut du setup **************************
void setup()
{
Serial.begin(9600); // moniteur serie : 9600 baud
delay(250);
compteur200ms = millis(); // Enregistrement de mon point de départ
compteur1000ms = millis(); // Enregistrement de mon point de départ
SetupEthernet();
}
// ********************** debut de la boucle **************************
void loop()
{
if((millis()-compteur200ms)>= 200L) // si 200 ms se sont écoulées
{
compteur200ms = millis(); // nouvel enregistrement du compteur
}
if((millis()-compteur1000ms)>= 1000L) // si 1s se sont écoulées
{
compteur1000ms = millis(); // nouvel enregistrement du compteur
GoogleSheet();
}
}
// ********************** fin de la boucle **************************
void GoogleSheet()
{
Serial.println("Google");
data+="";
data+="Evenements";
data+="Essai";
//EthernetClient client = server.available();
if (client.connected())
{
Serial.println("connected");
client.print("POST /formResponse?formkey=");
client.print(formkey);
client.println("&ifq HTTP/1.1");
client.println("Host: spreadsheets.google.com");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
//Show on serial monitor
Serial.print("POST /formResponse?formkey=");
Serial.print(formkey);
Serial.println("&ifq HTTP/1.1");
Serial.println("Host: spreadsheets.google.com");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.println("Connection: close");
Serial.print("Content-Length: ");
Serial.println(data.length());
Serial.println();
Serial.print(data);
Serial.println();
client.stop();
}
}
void SetupEthernet()
{
#if SERIAL
Serial.println("INIT Ethernet");
#endif
Ethernet.begin(ArduinoMAC, ArduinoIPAddress);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
#if SERIAL
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
#endif
//defaut_init_ethernet = true;
}
if (Ethernet.linkStatus() == LinkOFF)
{
//defaut_init_ethernet = true;
#if SERIAL
Serial.println("Ethernet cable is not connected.");
#endif
}
#if SERIAL
Serial.print(F(" > IP Serveur : "));
Serial.println (Ethernet.localIP ());
Serial.print(F(" > subnetMask : "));
Serial.println (Ethernet.subnetMask ());
Serial.print(F(" > gatewayIP : "));
Serial.println (Ethernet.gatewayIP ());
Serial.print(F(" > dnsServerIP : "));
Serial.println (Ethernet.dnsServerIP ());
Serial.println("=== Fin Initialisation ETHERNET====");
Serial.println("");
#endif
delay(1000);
}
Je ne connais pas cette bibliothèque donc je ne peux faire que des conjectures. Tu déclares un client ici
EthernetClient client;
Mais tu ne fais jamais de
client.connect() ;
Par contre il y a un
Ethernet.begin
mais je ne vois pas de déclaration d'un objet appelé Ethernet...
Es-tu sûr que ça compile ? Tu as dû faire ton code à partir de morceaux dont les noms des objets ne sont pas cohérents. Soit tu conserves client, soit Ethernet mais il faut en choisir un...
Merci pour ces réponses.
J'ai essayé de mettre de l'ordre dans mon programme et installé la librairie Wiz Ethernet, mais toujours le même problème.
Pour info, c'est un shield W5100 (et non un W5500).
Quel est encore le problème ?
#include <Ethernet.h> // librairie pour la carte ethernet W5100
#include <SPI.h> // librairie pour la communication avec la carte ethernet
//#include <DS3231.h>
//#include <Wire.h>
char formkey[] = " xxxx"; //Replace with your Key
byte mac[] = { 0xDE, 0xEF, 0x14, 0x05, 0xFE, 0xAB };
// assign an IP address for the controller:
IPAddress ip(192,168,1,31);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
// initialize the library instance:
EthernetClient client;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
unsigned long compteur1000ms; //Compteur pour interruption
unsigned long compteur200ms; //Compteur pour interruption
String data;
#define SERIAL 1 // 1 pour activer trace sur port série, 0 pour la désactiver
// ********************** debut du setup **************************
void setup()
{
Serial.begin(9600); // moniteur serie : 9600 baud
delay(250);
compteur200ms = millis(); // Enregistrement de mon point de départ
compteur1000ms = millis(); // Enregistrement de mon point de départ
SetupEthernet();
}
// ********************** debut de la boucle **************************
void loop()
{
if((millis()-compteur200ms)>= 200L) // si 200 ms se sont écoulées
{
compteur200ms = millis(); // nouvel enregistrement du compteur
}
if((millis()-compteur1000ms)>= 1000L) // si 1s se sont écoulées
{
compteur1000ms = millis(); // nouvel enregistrement du compteur
GoogleSheet();
}
}
// ********************** fin de la boucle **************************
void GoogleSheet()
{
Serial.println("Google");
data+="";
data+="Evenements";
data+="Essai";
// Create a client connection
EthernetClient client = server.available();
if (client)
{
Serial.println("connected");
client.print("POST /formResponse?formkey=");
client.print(formkey);
client.println("&ifq HTTP/1.1");
client.println("Host: spreadsheets.google.com");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
//Show on serial monitor
Serial.print("POST /formResponse?formkey=");
Serial.print(formkey);
Serial.println("&ifq HTTP/1.1");
Serial.println("Host: spreadsheets.google.com");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.println("Connection: close");
Serial.print("Content-Length: ");
Serial.println(data.length());
Serial.println();
Serial.print(data);
Serial.println();
client.stop();
}
}
void SetupEthernet()
{
#if SERIAL
Serial.println("INIT Ethernet");
#endif
Ethernet.begin(mac, ip);
#if SERIAL
Serial.print(F(" > IP Serveur : "));
Serial.println (Ethernet.localIP ());
Serial.print(F(" > subnetMask : "));
Serial.println (Ethernet.subnetMask ());
Serial.print(F(" > gatewayIP : "));
Serial.println (Ethernet.gatewayIP ());
Serial.print(F(" > dnsServerIP : "));
Serial.println (Ethernet.dnsServerIP ());
Serial.println("=== Fin Initialisation ETHERNET====");
Serial.println("");
#endif
delay(1000);
server.begin();
delay(1000);
}
Voilà, j'arrive enfin à me connecter, mais maintenant impossible d'écrire dans la feuille googleSheet.
SI je tape directement la syntaxe dans mon PC cela fonctionne, mais pas avec mon arduino. Il doit manquer une syntaxe
Je n'y connais pas grand chose mais en cherchant un peu, avec les mots clés arduino google sheet, on trouve pas mal de tutos. Ils sont souvent sur ESP8266 pour l'accès internet par Wi-Fi.
Celui-ci est l'un des plus proches de ton besoin, mais il y en a bien d'autres. Il faut faire un GET pour envoyer ta requête au serveur Google docs, utiliser l'URL directement ne marche pas.
Oui tout les tuto que l'on trouve sur internet son avec le module ESP8666. Moi je préfère rester en filaire vu que ce module sera à l'extérieur, donc le wifi pas terrible.
L'accès en HTTPS, je sais pas il faudra que je regarde.
Merci pour ces pistes, je vais creuser.
Il exite aussi une solution en passant par PushingBox, mais je voulais éviter également