Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #define DEBUG true
- #define MAX_STRING 500
- SoftwareSerial wifi(3,2);
- char reply[MAX_STRING];
- void setup() {
- Serial.begin(115200);
- wifi.begin(115200);
- sendCommand("AT\r\n", 2000);
- sendCommand("AT+CWMODE?\r\n", 2000);
- //sendCommand("AT+GMR\r\n",2000);
- sendCommand("AT+CWMODE=2\r\n", 2000);
- sendCommand("AT\r\n", 2000);
- Serial.print("\n\nFINE");
- }
- void loop() {
- }
- void sendCommand(String cmd, int timeout){
- wifi.print(cmd);
- readSerial(timeout);
- }
- void readSerial(int timeout){
- long int time = millis();
- int i=0;
- while( (time+timeout) > millis() ){
- while(wifi.available()){
- char c = wifi.read();
- reply[i++]=c;
- }
- }
- reply[i]='\0';
- if(DEBUG)
- Serial.print(reply);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement