 #include <spiffs/spiffs.h>
 
 #define ZIMODEM_VERSION "0.1"
+#define null 0
 
 class ZMode
 {

  return WiFi.status() == WL_CONNECTED;
}

class ZCommand : public ZMode
{
  const int MAX_COMMAND_SIZE=256;
  
  public:
    void serialIncoming()
    {
      uint8_t sbuf[MAX_COMMAND_SIZE];
      memset(sbuf,0,MAX_COMMAND_SIZE);
      int n = Serial.readBytesUntil('\n',sbuf, MAX_COMMAND_SIZE);
      if((n > 0)&&(sbuf[n-1]=='\r'))
        sbuf[--n]=0;
      if(n > 0)
      {
        if((n>1)
        &&((sbuf[0]=='A')||(sbuf[0]=='a'))
        &&((sbuf[1]=='T')||(sbuf[1]=='t')))
        {
          if(n == 2)
            Serial.println("OK");
          else
          {
            int index=2;
            char lastCmd=' ';
            int result=0;
            int vstart=0;
            int vlen=0;
            while(index<n)
            {
              lastCmd=sbuf[index++];
              vstart=index;
              vlen=0;
              if(index<n)
              {
                if(sbuf[index]=='\"')
                {
                  vstart++;
                  while((++index<n)&&(sbuf[index]!='\"'))
                    vlen++;
                }
                else
                while((index<n)
                &&(! (((sbuf[index]>='a')&&(sbuf[index]<='z'))
                   ||((sbuf[index]>='A')&&(sbuf[index]<='Z')))))
                {
                  vlen++;
                  index++;
                }
              }
              int vval=0;
              uint8_t vbuf[vlen+1];
              memset(vbuf,0,vlen+1);
              if(vlen > 0)
              {
                memcpy(vbuf,sbuf+vstart,vlen);
                vval=atoi((char *)vbuf);
              }
              switch(lastCmd)
              {
              case 'w':
              case 'W':
              {
                if((vlen==0)||(vval>0))
                {
                  int n = WiFi.scanNetworks();
                  if((vval > 0)&&(vval < n))
                    n=vval;
                  for (int i = 0; i < n; ++i)
                  {
                    Serial.print(WiFi.SSID(i));
                    Serial.print(" (");
                    Serial.print(WiFi.RSSI(i));
                    Serial.print(")");
                    Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
                    delay(10);
                  }
                }
                else
                {
                  char *x=strstr((char *)vbuf,",");
                  if(x <= 0)
                    result=1;
                  else
                  {
                    *x=0;
                    char *ssi=(char *)vbuf;
                    char *pw=x+1;
                    if(!connectWifi(ssi,pw))
                      result=1;
                    else
                    {
                      File f = SPIFFS.open("/zconfig.txt", "w");
                      f.print(ssi);
                      f.print(",");
                      f.print(pw);
                      f.close();
                    }
                  }
                }
                break;
              }
              default:
                break;
              }
            }
            switch(result)
            {
            case 0:
              Serial.println("OK");
              break;
            case 1:
              Serial.println("ERROR");
              break;
            default:
              break;
            }
          }
        }
        else
          Serial.println("ERROR");
      }
    }

    void loop()


void setup() 
{
  delay(10);
  SPIFFS.begin();
  String msg;
  String argv[10];
  if(!SPIFFS.exists("/zconfig.txt"))
  {
    msg="INITAILIZED\r\n";
    SPIFFS.format();
    File f = SPIFFS.open("/zconfig.txt", "w");
    f.printf(",,115200");
    f.close();
  }
  else
