Bonjour,
j'ai donc commencé à expérimenter avec le coffret Franzis Maker Kit IOT
La boite contient une carte Pretzel Wifi, c'est une carte compatible Arduino Nano (Nano ESP) avec module ESP8266 WIFI.
J'ai installé le driver série USB CH340G, ainsi que l'IDE Arduino 1.8.12, avec mon PC sous Windows 7 pro 64.
Pour la configuration :
- Type de carte "Arduino Nano"
- Processeur "ATmega328P (Old Bootloader)"
- Port: "COM6"
- Programmateur "USBasp"
J'ai suivit les premiers exemples.
On arrive à un truc intéressant avec l'horloge TCP.
J'ai adapté le code pour me familiariser avec l'outil, ça fonctionne :
#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 ce que ça donne :
Mais quand je souhaite remplacer la ligne :
sweekday = String(weekday()) + " Jeudi";
par le code suivant :
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 :
(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)
Je viens de passer l'après midi sur ce problème sans comprendre pourquoi ça ne fonctionne pas...
Avez-vous une piste ?
Merci
A bientôt