Skip to content

Instantly share code, notes, and snippets.

@rhaseven7h
Created July 18, 2018 22:57
Show Gist options
  • Save rhaseven7h/cc19fc1fd9ba64586497999e6e3f5f7a to your computer and use it in GitHub Desktop.
Save rhaseven7h/cc19fc1fd9ba64586497999e6e3f5f7a to your computer and use it in GitHub Desktop.
void handleSerialComms() {
while (Serial1.available()) {
char inByte = Serial1.read();
Serial.write(inByte);
}
while (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
void sendCmd(String s) {
Serial1.println(s);
handleSerialComms();
}
void sendCmdExpect(String s, String x) {
Serial1.println(s);
Serial1.flush();
Serial.println("Executing ["+s+"]");
if (Serial1.find(const_cast<char*>(x.c_str()))) {
Serial.println("Successfully executed ["+s+"]");
} else {
Serial.println("Timeout executing ["+s+"]");
}
handleSerialComms();
}
void setup() {
pinMode(8, OUTPUT);
digitalWrite(8, HIGH);
Serial.begin(115200);
Serial.println("Booting up...");
Serial1.setTimeout(60000);
Serial1.begin(115200);
Serial.println("Waiting for WiFi Module to be ready...");
if (Serial1.find("ready")) {
Serial.println("WiFi Module is ready!");
handleSerialComms();
} else {
Serial.println("WiFi Module timed out while waiting for it to be ready.");
}
sendCmdExpect("AT", "OK");
sendCmdExpect("AT+RST", "ready");
sendCmdExpect("AT+CWMODE_DEF=3", "OK");
sendCmdExpect("AT+CWMODE_CUR=3", "OK");
sendCmdExpect("AT+CWMODE=3", "OK");
sendCmdExpect("AT+CWAUTOCONN=0", "OK");
sendCmdExpect("AT+CWQAP", "OK");
sendCmdExpect("AT+CWLAP", "OK");
sendCmdExpect("AT+CWJAP=\"AFRODITA\",\"A38sJjf3X7ByyFJ3\"", "OK");
sendCmdExpect("AT+CIFSR", "OK");
sendCmdExpect("AT+CIPMUX=1", "OK");
sendCmdExpect("AT+CIPSERVER=1,9981", "OK");
sendCmdExpect("AT", "OK");
}
void loop() {
handleSerialComms();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment