Wifi

  • Explication

 

  • Prerequisites
    • Dossier partager all user

 

  • Manipulation
//Librairie
#include <OLED_I2C.h>
#include<Wire.h>

//Declaration

OLED  myOLED(SDA, SCL);
////In
int relay = 5;
////Variable
String ChainR;
boolean OK = false;
void bp(void);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
//////ESP
int error = 0;
int iESP = 0;
boolean Me = 0;




void setup() {

  pinMode(relay, OUTPUT);
  pinMode(9, OUTPUT);
  Serial.begin(115200);
  //Oled
  if (!myOLED.begin(SSD1306_128X64))
    while (1);
  myOLED.setFont(SmallFont);

  myOLED.clrScr();
  myOLED.print("TEST ESP", LEFT, 1);

  myOLED.update();
  while (OK == false) {
    Serial.println("AT");
    delay(500);
    serialEvent();
    myOLED.print(ChainR, LEFT, 10);
    myOLED.update();
    ChainR = "";
  }
  OK = false;
  //////CWMODE
  while (OK == false) {
    Serial.println("AT+CWMODE=3");
    delay(500);
    serialEvent();
    myOLED.print(ChainR, LEFT, 20);
    myOLED.update();
    ChainR = "";
  }
  OK = false;
  //////CWJAP
  while (OK == false) {
    //VEGAIOT
    //I634SGvk
    Serial.println("AT+CWJAP=\"ICAN\",\"Blue1478$\"");
    delay(3000);
    serialEvent();
    myOLED.print(ChainR, LEFT, 40);
    myOLED.update();
    ChainR = "";
  }
  OK = false;
  ///FIN esp
  myOLED.clrScr();
  myOLED.print(ChainR, LEFT, 50);
  myOLED.update();
  delay(5000);
  Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.190\",2222");
  delay(5000);
}

void loop() {

/*
  myOLED.print("Initialize", LEFT, 20);
  myOLED.update();
  Serial.println("AT+CIPSEND=4");
  delay(5000);

  myOLED.print("Send", LEFT, 30);
  myOLED.update();
  Serial.println("toto");
  delay(5000);*/
}

//Event
void serialEvent(void) {
  while (Serial.available()) {
    char CaractR = Serial.read();
    ChainR += CaractR;
    if (ChainR.indexOf("OK") >= 0) {
      OK = true;
    }

    if (ChainR.indexOf("+IPD") >= 0) {
      //int 2p = ChainR.indexOf(":");
      ChainR = ChainR.substring(ChainR.indexOf(":"));
      myOLED.clrScr();
      myOLED.print(ChainR, LEFT, 10);
      myOLED.update();

      if (ChainR.indexOf("relayon") >= 0) {
        digitalWrite(relay, HIGH);
        ChainR = "";
        myOLED.print("ON", LEFT, 20);
        myOLED.update();
      }
      else {
        if (ChainR.indexOf("relayoff") >= 0) {
          digitalWrite(relay, LOW);
          ChainR = "";
          myOLED.print("OFF", LEFT, 20);
          myOLED.update();

        }
        else {
          if (ChainR.indexOf("benjamin") >= 0) {
            digitalWrite(9, HIGH);
            ChainR = "";
            myOLED.print("OFF", LEFT, 20);
            myOLED.update();
          }
          else {
            if (ChainR.indexOf("benjaoff") >= 0) {
              digitalWrite(9, LOW);
              ChainR = "";
              myOLED.print("OFF", LEFT, 20);
              myOLED.update();
            }
          }
        }
      }
    }
  }
}

    //Conoir Benjamin
    //Conoir.com
    //A changer le code, le prof la vue et le connait.
    //Changer les variable et le sens des if
    //Faire attention au code et a la comprehension du code pour l utiliser au mieux
    //Merci pour la jup. bye
  • Conclusion