Guest User

Untitled

a guest
Jan 21st, 2017
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #define DEBUG true
  3. #define MAX_STRING 500
  4. SoftwareSerial wifi(3,2);
  5.  
  6. char reply[MAX_STRING];
  7.  
  8. void setup() {
  9.   Serial.begin(115200);
  10.     wifi.begin(115200);
  11.     sendCommand("AT\r\n", 2000);
  12.     sendCommand("AT+CWMODE?\r\n", 2000);
  13.     //sendCommand("AT+GMR\r\n",2000);
  14.     sendCommand("AT+CWMODE=2\r\n", 2000);
  15.     sendCommand("AT\r\n", 2000);
  16.   Serial.print("\n\nFINE");
  17.  
  18. }
  19.  
  20. void loop() {
  21.  
  22. }
  23.  
  24. void sendCommand(String cmd, int timeout){
  25.   wifi.print(cmd);
  26.   readSerial(timeout);
  27. }
  28.  
  29. void readSerial(int timeout){
  30.   long int time = millis();
  31.   int i=0;
  32.   while( (time+timeout) > millis() ){
  33.        while(wifi.available()){
  34.           char c = wifi.read();
  35.           reply[i++]=c;
  36.        }  
  37.    }
  38.    reply[i]='\0';
  39.    if(DEBUG)
  40.       Serial.print(reply);
  41.      
  42. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×