Bonjour à tous,

Je commence à travailler avec le coffret "Franzis Maker Kit IOT".
Il est basé sur une carte "Pretzel Wifi", c'est une carte compatible Arduino Nano (Nano ESP) avec module ESP8266 WIFI.

Je code avec l'IDE Arduino v1.8.12 sous Windows 7 pro 64, configuré comme suit :
- Type de carte "Arduino Nano"
- Processeur "ATmega328P (Old Bootloader)"
- Programmateur "USBasp"

On arrive à un truc intéressant avec l'horloge TCP.
La carte Pretzel est configurée en client Wifi qui se connecte régulièrement à un site web qui donne l'heure atomique, la carte affiche l'heure et la date sur un écran à cristaux liquides de 2 lignes de 16 caractères.

J'ai adapté le code pour me familiariser avec la carte et le langage C Arduino.
Je voulais afficher le nom du jour, et le mois en toutes lettres. Ca fonctionne :

Code : 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include <SD.h>
 
#define SSID "XXXX"
#define PASSWORD "MA_CLEF_WEP"
 
#define DEBUG true
 
#define LED_WLAN 13
 
#include <SoftwareSerial.h>
#include <TimeLib.h>
#include <LiquidCrystal.h>
 
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
SoftwareSerial esp8266(11, 12); // RX, TX
 
void setup() {
  Serial.begin(19200);
  esp8266.begin(19200);
 
 
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Horloge Web");
 
 
  if (!espConfig()) serialDebug();
  else digitalWrite(LED_WLAN, HIGH);
 
 
  lcd.setCursor(0, 1);
  lcd.print("Liaison WIFI OK");
 
 
  getTime("chronic.herokuapp.com", "/utc/in+two+hours"); //Gets Time from Page and Sets it
}
 
void loop() {
  String shour, sminute, ssecond, sday, smonth, sweekday;
 
  delay(1000);
 
  if (hour() <= 9) shour = "0" + String(hour()); else shour = String(hour()); // adjust for 0-9
  if (minute() <= 9) sminute = "0" + String(minute());  else sminute = String(minute());
  if (second() <= 9) ssecond = "0" + String(second());  else ssecond = String(second());
 
sweekday = String(weekday()) + " Jeudi";
 
  String Time =  shour + "h" + sminute + ":" + ssecond + " " + sweekday;
 
sday = String(day());
switch (month()) {
  case 1:
    smonth = "janvier";
    break;
  case 2:
    smonth = "fevrier";
    break;
  case 3:
    smonth = "mars";
    break;
  case 4:
    smonth = "avril";
    break;
  case 5:
    smonth = "mai";
    break;
  case 6:
    smonth = "juin";
    break;
  case 7:
    smonth = "juillet";
    break;
  case 8:
    smonth = "aout";
    break;
  case 9:
    if (sday.length()>1) {
      smonth = "septembr";  
    } else {
      smonth = "septembre";
    }
    break;
  case 10:
    smonth = "octobre";
    break;
  case 11:
    smonth = "novembre";
    break;
  default:
    smonth = "decembre";
    break;
}
 
  String Date = sday + " " + smonth + " " + String(year()) ;
 
  int LgTxt;
  int NbSp;
  LgTxt = Date.length();
  if (LgTxt<16) {
    NbSp = (16 - LgTxt) / 2;
    for (int i=1;i<=NbSp;i++) {
      Date = " " + Date;    
    }
    NbSp = 16 - LgTxt - NbSp;
    for (int i=1;i<=NbSp;i++) {
      Date = Date + " ";
    }
  }
 
  debug(Date);
  debug(Time);
 
  lcd.setCursor(0, 0);
  lcd.print(Time);
 
  lcd.setCursor(0, 1);
  lcd.print(Date);
 
}
 
 
String getTCP(String Host, String Subpage)
{
  boolean success = true;
 
  success &= sendCom("AT+CIPSTART=\"TCP\",\"" + Host + "\",80", "OK");
  String getRequest = "GET " + Subpage + " HTTP/1.1\r\nHost:" + Host + "\r\n\r\n";
  success &= sendCom("AT+CIPSEND=" + String(getRequest.length() + 2), ">");
 
  return sendCom(getRequest);
}
 
boolean getTime(String Host, String Subpage)
{
  boolean success = true;
  int xyear, xmonth, xday, xhour, xminute, xsecond;  //lokal variables
 
  success &= sendCom("AT+CIPSTART=\"TCP\",\"" + Host + "\",80", "OK");
  String getRequest = "GET " + Subpage + " HTTP/1.1\r\nHost:" + Host + "\r\n";
  success &= sendCom("AT+CIPSEND=" + String(getRequest.length() + 2), ">");
 
  esp8266.println(getRequest);
 
  if (esp8266.find("+IPD"))
  {
    if (esp8266.find("\r\n\r\n"))
    {
      xyear = esp8266.parseInt();
      xmonth = esp8266.parseInt();
      xday = esp8266.parseInt();
      xhour = esp8266.parseInt();
      xminute = esp8266.parseInt();
      xsecond = esp8266.parseInt();
 
      if (xday < 0) xday *= -1;          //Because of date seperator - parseInt detects negativ integer
      if (xmonth < 0) xmonth *= -1;    //Because of date seperator - parseInt detects negativ integer
 
 
      setTime(xhour, xminute, xsecond, xday, xmonth, xyear);
      sendCom("AT+CIPCLOSE", "OK");
      return true;
    }
    else return false;
  }
  else return false;
}
 
//-----------------------------------------Config ESP8266------------------------------------
 
boolean espConfig()
{
  boolean success = true;
  esp8266.setTimeout(5000);
  success &= sendCom("AT+RST", "ready");
  esp8266.setTimeout(1000);
  if (configStation(SSID, PASSWORD)) {
    success &= true;
    debug("WLAN Connected");
    debug("My IP is:");
    debug(sendCom("AT+CIFSR"));
  }
  else
  {
    success &= false;
  }
  //shorter Timeout for faster wrong UPD-Comands handling
  success &= sendCom("AT+CIPMODE=0", "OK");  //So rum scheit wichtig!
  success &= sendCom("AT+CIPMUX=0", "OK");
 
  return success;
}
 
boolean configTCPServer()
{
  boolean success = true;
 
  success &= (sendCom("AT+CIPMUX=1", "OK"));
  success &= (sendCom("AT+CIPSERVER=1,80", "OK"));
 
  return success;
 
}
 
boolean configTCPClient()
{
  boolean success = true;
 
  success &= (sendCom("AT+CIPMUX=0", "OK"));
  //success &= (sendCom("AT+CIPSERVER=1,80", "OK"));
 
  return success;
 
}
 
 
boolean configStation(String vSSID, String vPASSWORT)
{
  boolean success = true;
  success &= (sendCom("AT+CWMODE=1", "OK"));
  esp8266.setTimeout(20000);
  success &= (sendCom("AT+CWJAP=\"" + String(vSSID) + "\",\"" + String(vPASSWORT) + "\"", "OK"));
  esp8266.setTimeout(1000);
  return success;
}
 
boolean configAP()
{
  boolean success = true;
 
  success &= (sendCom("AT+CWMODE=2", "OK"));
  success &= (sendCom("AT+CWSAP=\"NanoESP\",\"\",5,0", "OK"));
 
  return success;
}
 
boolean configUDP()
{
  boolean success = true;
 
  success &= (sendCom("AT+CIPMODE=0", "OK"));
  success &= (sendCom("AT+CIPMUX=0", "OK"));
  success &= sendCom("AT+CIPSTART=\"UDP\",\"192.168.255.255\",90,91,2", "OK"); //Importand Boradcast...Reconnect IP
  return success;
}
 
//-----------------------------------------------Controll ESP-----------------------------------------------------
 
boolean sendUDP(String Msg)
{
  boolean success = true;
 
  success &= sendCom("AT+CIPSEND=" + String(Msg.length() + 2), ">");    //+",\"192.168.4.2\",90", ">");
  if (success)
  {
    success &= sendCom(Msg, "OK");
  }
  return success;
}
 
 
boolean sendCom(String command, char respond[])
{
  esp8266.println(command);
  if (esp8266.findUntil(respond, "ERROR"))
  {
    return true;
  }
  else
  {
    debug("ESP SEND ERROR: " + command);
    return false;
  }
}
 
String sendCom(String command)
{
  esp8266.println(command);
  return esp8266.readString();
}
 
 
void serialDebug() {
  while (true)
  {
    if (esp8266.available())
      Serial.write(esp8266.read());
    if (Serial.available())
      esp8266.write(Serial.read());
  }
}
 
void debug(String Msg)
{
  if (DEBUG)
  {
    Serial.println(Msg);
  }
}
Voici une photo de la carte en fonctionnement (le port USB assure l'alimentation, la programmation via le PC et le monitoring série) :

Nom : Pretzel.jpg
Affichages : 239
Taille : 316,5 Ko

Mais quand je souhaite remplacer la ligne :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
sweekday = String(weekday()) + " Jeudi";
par le code suivant :

Code : 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
switch (weekday()) {
//switch (second()%7+1) {
  case 1:
    sweekday = "Dimanch";
    break;
  case 2:
    sweekday = "  Lundi";
    break;
  case 3:
    sweekday = "  Mardi";
    break;
  case 4:
    sweekday = "Mercred";
    break;
  case 5:
    sweekday = "  Jeudi";
    break;
  case 6:
    sweekday = "Vendred";
    break;
  default:
    sweekday = " Samedi";
    break;
}
Ca ne marche plus !

Ca compile sans soucis, ça se téléverse sans soucis, mais l'afficheur LCD reste bloqué sur "Horloge Web"

Je ne vois pas le message "Liaison WIFI OK", ni l'heure et la date qui s'affiche ensuite dans le LCD

Le moniteur série reste lui aussi muet, mais il réagit normalement si je lui tape une commande comme par exemple "AT+GMR"

20:12:05.376 -> AT+GMR
20:12:05.376 -> AT version:0.22.0.0(Mar 20 2015 10:04:26)
20:12:05.410 -> SDK version:1.0.0
20:12:05.410 -> compile time:Mar 20 2015 11:00:32
20:12:05.410 ->
20:12:05.410 -> OK

Bizarrement dans le menu admin de ma freebox, je vois que ma carte PRETZEL est connectée, et qu'elle communique chaque seconde :

Nom : Freebox.jpg
Affichages : 213
Taille : 204,4 Ko

(c'est la carte "Espressif Inc.")

Donc c'est à moitié planté
- l'affichage ne se fait plus sur l'écran LCD ni sur le moniteur série
- mais la carte continuer à tourner, elle accède à Internet régulièrement et elle réagit aux commandes du terminal...

Je viens de passer l'après midi sur ce problème sans comprendre pourquoi ça ne fonctionne pas...

Je pense que c'est lié à la bibliothèque de l'afficheur car si dans le code qui marche bien je remplace "Horloge Web" par "Horloge Internet" (texte faisant pile 16 caractères) ça plante de la même façon

La bibliothèque LCD doit planter quelque chose au niveau des entrées sorties, peut-être à cause d'un problème de mémoire mais je ne sais pas quoi !

Avez-vous une piste ?

Merci

A bientôt