Bonjour,

J'ai un soucis avec mon code.

J'ai branché par ethernet mon arduiono uno avec un ethernet shield officiel sur le port ethernet de mon ordinateur.
Je n'ai rien configurer d'autres.

Je cherche à envoyer par GET mes données de téléinfo sur la base de donnée Mysql de mon serveur personnel.
La page "send_data.php" recevant les données et les insérant dans la base de donnée.

Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xF9, 0x81 };
IPAddress ip(192, 168, 0, 16);

char server[] = "www.martin_valentin.fr";
EthernetClient client;

SoftwareSerial cptSerial(2, 3);
#define startFrame 0x02
#define endFrame 0x03
#define startLine 0x0A
#define endLine 0x0D

void setup()
{
  cptSerial.begin(1200);
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
}

String GetTeleInfo()
{
    String TeleInfo = "";
    char charIn = 0;
    while (charIn != startLine)
    {
        charIn = cptSerial.read() & 0x7F;
    }
    while (charIn != endLine)
    {
        if (cptSerial.available() > 0)
        {
            charIn = cptSerial.read() & 0x7F;
            TeleInfo += charIn;
        }
    }
    return TeleInfo;
}

String ShowTeleInfo(String keyword, String unit, int length)
{
    int essai = 0;
    // Nombre d'étiquettes maximum, cf documentation ERDF
    int max_essais = 33;
    String data = "";
    String msg = "";
    while(data.substring(0,keyword.length()) != keyword && essai != max_essais)
    {
        data = GetTeleInfo();
        essai++;
    }
    msg = "\t<";
    msg += keyword;
    msg += " unit=\"";
    msg += unit;
    msg += "\">";
    if (essai != max_essais)
    {
        msg += data.substring((keyword.length() + 1),(length + (keyword.length() + 1)));
    }
    else
    {
        msg += "NA";
    }
    msg += "</";
    msg += keyword;
    msg += ">";
    return msg;
}

void loop()
{
  boolean current_line_is_blank = true;
  if(client.connect(server, 80)) {
    Serial.println("-> Connected");
    char c = client.read();
    if (c == '\n' && current_line_is_blank)
    {
      client.print("GET /teleinfo/send_data.php?");
      client.print("ADCO=");
      client.print(ShowTeleInfo("ADCO","",12));
      client.print("&&");
      client.print("OPTARIF=");
      client.print(ShowTeleInfo("OPTARIF","",4));
      client.print("&&");
      client.print("ISOUSC=");
      client.print(ShowTeleInfo("ISOUSC","A",2));
      ...
      client.println(" HTTP/1.1");
      client.println("Host: www.martin_valentin.fr");
      client.println("Connection: close");
      client.println();
      client.println();
      client.stop();
      }
    if (c == '\n')
    {
        current_line_is_blank = true;
    }
    else if (c != '\r')
    {
        current_line_is_blank = false;
    }
  } else {
    Serial.println("--> connection failed\n");
  }
  delay(200);
  client.stop();
}

Mon soucis est que dans loop(), l'envoie ne se fait pas et m'affiche directement "--> connection failed".
Je pense donc avoir mal configuré mon ethernet ou il manque une info mais je ne vois pas où est le soucis.

Je vous remercie d'avance pour votre aide

Valentin