boolean WIFI::confServer(byte mode, int port)
{
    _cell.print("AT+CIPSERVER=");  
    _cell.print(String(mode));
    _cell.print(",");
    _cell.println(String(port));

    String data;
    unsigned long start;
	start = millis();
	boolean found = false;
	while (millis()-start<3000) {
     if(_cell.available()>0)
     {
     char a =_cell.read();
     data=data+a;
     }
     if (data.indexOf("OK")!=-1 || data.indexOf("no charge")!=-1)
     {
		found = true;
         break;
     }
  }
  return found;
}
/*************************************************************************
//inquire the current mode of wifi module

	return:	string of current mode
		Station
		AP
		AP+Station

***************************************************************************/
String WIFI::showMode()
{
    String data;
    _cell.println("AT+CWMODE?");  
	unsigned long start;
	start = millis();
    while (millis()-start<2000) {
     if(_cell.available()>0)
     {
     char a =_cell.read();
     data=data+a;
     }
     if (data.indexOf("OK")!=-1)
     {
         break;
     }
  }
    if(data.indexOf("1")!=-1)
    {
        return "Station";
    }else if(data.indexOf("2")!=-1)
    {
            return "AP";
    }else if(data.indexOf("3")!=-1)
    {
         return "AP+Station";
    }
}
Example #3
0
TparameterResult ApplicationMQTTClient::dissectParameter(String Parameter){

	TparameterResult par;
	par.count = 0;
    for (int i = 0; i < 11; i++) {
    	par.item[i] = "";
    }

    String str = Parameter;

    int index = -1;
    int i = 0;

    do{
     index = str.indexOf(",");
     if (index != -1){
    	 par.item[i] = str.substring(0, index);
         //Serial.println("Parameter[" + String(i) + "] = " + par.item[i]);
         str.remove(0, index +1);
         i++;
         if (str.indexOf(",") == -1 and str.length() > 0){    //best of the rest
        	 index = -1;
        	 par.item[i] = str;
        	 //Serial.println("Parameter[" + String(i) + "] = " + par.item[i]);
        	 i++;
         }
  	  }else{
  	  }
    } while (index != -1);

    par.count = i;
    return par;

}
/*************************************************************************
//Set up tcp or udp connection	(signle connection mode)

	type:	tcp or udp
	
	addr:	ip address
	
	port:	port number
		

	return:
		true	-	successfully
		false	-	unsuccessfully

***************************************************************************/
boolean WIFI::newMux(byte type, String addr, int port)

{
    String data;
    _cell.print("AT+CIPSTART=");
    if(type>0)
    {
        _cell.print("\"TCP\"");
    }else
    {
        _cell.print("\"UDP\"");
    }
    _cell.print(",");
    _cell.print("\"");
    _cell.print(addr);
    _cell.print("\"");
    _cell.print(",");
//    _cell.print("\"");
    _cell.println(String(port));
//    _cell.println("\"");
    unsigned long start;
	start = millis();
	while (millis()-start<3000) { 
     if(_cell.available()>0)
     {
     char a =_cell.read();
     data=data+a;
     }
     if (data.indexOf("OK")!=-1 || data.indexOf("ALREAY CONNECT")!=-1 || data.indexOf("ERROR")!=-1)
     {
         return true;
     }
  }
  return false;
}
/*************************************************************************
//show the parameter of ssid, password, channel, encryption in AP mode
		
		return:
			mySAP:<SSID>,<password>,<channel>,<encryption>

***************************************************************************/
String WIFI::showSAP()
{
    _cell.println("AT+CWSAP?");  
      String data;
      unsigned long start;
	start = millis();
    while (millis()-start<3000) {
       if(_cell.available()>0)
       {
       char a =_cell.read();
       data=data+a;
       }
       if (data.indexOf("OK")!=-1 || data.indexOf("ERROR")!=-1 )
       {
           break;
       }
    }
      char head[4] = {0x0D,0x0A};   
      char tail[7] = {0x0D,0x0A,0x0D,0x0A};        
      data.replace("AT+CWSAP?","");
      data.replace("+CWSAP","mySAP");
      data.replace("OK","");
	  data.replace(tail,"");
      data.replace(head,"");
      
          return data;
}
Example #6
0
    sp<Retval> SSH2Fs::getContentType(String& sContentType){
        URI::FileInfo fi;
        fi.parse(m_sPath.toChars());
        const char* ext = fi.m_sExtension.toChars();
        String sType = HttpContentType::getContentType(ext);
        bool bUseEncode = false;
        if( sType.indexOf("text/")==0 ){
            bUseEncode = true;
        }else if( sType.indexOf("xml/")==0 ){
            bUseEncode = true;
        }else if( sType.indexOf("/xml")!=((dfw_size_t)-1) ){
            bUseEncode = true;
        }

        if(bUseEncode){
            const char* enc = System::encoding();
            if(enc){
                sContentType = String::format("%s; charset=%s"
                                            , sType.toChars(), enc);
            }else{
                sContentType = sType;
            }
        }else{
            sContentType = sType;
        }

        return NULL;
    }
Example #7
0
char* HttpServer::ParseUrl(char *str)
{
  int8_t r=-1;
  int8_t i = 0;
  int index = 4;
  int index1 = 0;
  int plen = 0;
  char ch = str[index];
  char clientline[CMDBUF];
  while( ch != ' ' && index < CMDBUF)
  {
    clientline[index1++] = ch;
    ch = str[++index];
  }
  clientline[index1] = '\0';

  // convert clientline into a proper
  // string for further processing
  String urlString = String(clientline);

  // extract the operation
  String op = urlString.substring(0,urlString.indexOf(' '));

  // we're only interested in the first part...
  urlString = urlString.substring(urlString.indexOf('/'), urlString.indexOf(' ', urlString.indexOf('/')));

  // put what's left of the URL back in client line
  urlString.toCharArray(clientline, CMDBUF);

  return clientline;
}
void CNCArduinostepsClass::serialcalibratedx(String calibrcommand) // установка dxX и dxY с парсингом команды по последовательному порту
{
	//String calibrationtemp = calibrcommand.substring(0, calibrcommand.indexOf('&'));
	String dxtemp = calibrcommand;
	//Serial.println(calibrationtemp);
	//Serial.println(dxtemp);
	//double calibrationXtemp = calibrationtemp.substring(0, calibrationtemp.indexOf('$')).toFloat();
	//Serial.println(calibrationXtemp);
	//double calibrationYtemp = calibrationtemp.substring(calibrationtemp.indexOf('$') + 1, calibrationtemp.length()).toFloat();
	//Serial.println(calibrationYtemp);
	double dxXtemp = dxtemp.substring(0, dxtemp.indexOf('$')).toFloat();
	//Serial.println(dxXtemp);
	double dxYtemp = dxtemp.substring(dxtemp.indexOf('$') + 1, dxtemp.length()).toFloat();
	//Serial.println(dxYtemp);
	//double calibrationXtemp = amountstri.substring(0, amountstri.indexOf('$')).toFloat();
	///Serial.println(amountstri.substring(0, amountstri.indexOf('$')));
	//double calibrationYtemp = amountstri.substring(amountstri.indexOf('$')+1, amountstri.indexOf('&')).toFloat();
	//Serial.println(amountstri.substring(amountstri.indexOf('$')+1, amountstri.indexOf('&')));
	//double dxXtemp = amountstri.substring(amountstri.indexOf('&')+1, amountstri.indexOf('$')).toFloat();
	//Serial.println(amountstri.substring(amountstri.indexOf('&')+1, amountstri.indexOf('$')));
	//double dxYtemp = amountstri.substring(amountstri.indexOf('$')+1, amountstri.indexOf('#')).toFloat();
	//Serial.println(amountstri.substring(amountstri.indexOf('$')+1, amountstri.indexOf('#')));
	//Serial.println(calibrationXtemp);
	//Serial.println(calibrationYtemp);
	//Serial.println(dxXtemp);
	//Serial.println(dxYtemp);
	//setcalibration(calibrationXtemp, calibrationYtemp);
	setdxdy(dxXtemp, dxYtemp);

}
String TicketflySDBeacon::TicketInfoParser (String TicketString, int typeReturn){ 
  String TicketNumberRetrieve = "", TicketNameRetrieve = "", TicketTypeRetrieve = "";
  int lengthString, commaIndex1, commaIndex2;
  TicketString.replace(" ", "");
  lengthString = TicketString.length();
  commaIndex1 = TicketString.indexOf(',');
  commaIndex2 = TicketString.indexOf(',', commaIndex1+1);
    switch (typeReturn){
      case 1:
        TicketNumberRetrieve = TicketString.substring (0, commaIndex1);
        return TicketNumberRetrieve;
        break;
      case 2:
        TicketNameRetrieve = TicketString.substring (commaIndex1+1, commaIndex2);
        return TicketNameRetrieve;
        break;
      case 3:
        TicketTypeRetrieve = TicketString.substring (commaIndex2+1, lengthString);
        return TicketTypeRetrieve;
        break;
      default:
        return "empty";
        Serial.println (F("this is not an acceptable input"));
        break;
    }
}
String Utility::findValue(String input, String key) {
  Serial.println("Got: " + input);

  String ret = "Key not found: " + key;
  int eqIndex = input.indexOf('=');
  while (eqIndex > -1) {
    String k = input.substring(0, eqIndex);
    Serial.println("Found key: " + k);
    String v;
    int ampIndex = input.indexOf('&');
    if (ampIndex > -1) {
      v = input.substring(eqIndex + 1, ampIndex);
      input = input.substring(ampIndex + 1);
    } else {
      v = input.substring(eqIndex + 1);
      input = v;
    }
    Serial.println("Found value: " + v);
    if (k.equals(key)) {
      ret = v;
      break;
    } else {
      eqIndex = input.indexOf('=');
    }
  }

  return ret;
}
Example #11
0
void NaughtyFilter::checkPICSagainstoption(String s, const char *l, int opt, std::string m)
{
	if (s.indexOf(l) != -1) {
		// if the rating contains the label then:
		int i = 0;
		// get the rating label value
		s = s.after(l);
		if (s.indexOf(" ") != -1) {
			//remove anything after it
			s = s.before(" ");
		}
		// sanity checking
		if (s.length() > 0) {
			i = s.toInteger();  // convert the value in a String to an integer
			if (opt < i) {	// check its value against the option in config file
				isItNaughty = true;  // must be over limit
				whatIsNaughty = m + " ";
				message_no = 1000;
				whatIsNaughty += o.language_list.getTranslation(1000);
				// PICS labeling level exceeded on the above site.
				whatIsNaughtyCategories = "PICS";
				whatIsNaughtyLog = whatIsNaughty;
			}
		}
	}
}
Example #12
0
String parsePath(String line) {
  int firstPathChar = line.indexOf(' ') + 1;
  int nextPathChar = line.indexOf(' ', (unsigned int) firstPathChar);
  if (nextPathChar == -1) {
    nextPathChar = line.length();
  }
  return line.substring((unsigned int) firstPathChar, (unsigned int) nextPathChar);
}
int GetMoveTimer()
{
    //Parse the int timer from the string
    String moveTimerString = slaveCommand.substring(slaveCommand.indexOf('[') + 1 ,slaveCommand.indexOf(']'));
    //Convert the string into a int.
    int moveTimerInt = moveTimerString.toInt();
    return moveTimerInt;
}
void ipArrayFromString(byte ipArray[], String ipString) {
  int dot1 = ipString.indexOf('.');
  ipArray[0] = ipString.substring(0, dot1).toInt();
  int dot2 = ipString.indexOf('.', dot1 + 1);
  ipArray[1] = ipString.substring(dot1 + 1, dot2).toInt();
  dot1 = ipString.indexOf('.', dot2 + 1);
  ipArray[2] = ipString.substring(dot2 + 1, dot1).toInt();
  ipArray[3] = ipString.substring(dot1 + 1).toInt();
}
Example #15
0
bool ESP8266::sATCIPCLOSEMulitple(uint8_t mux_id)
{
    String data;
    rx_empty();
    m_puart->print("AT+CIPCLOSE=");
    m_puart->println(mux_id);
    
    data = recvString("OK", "link is not", 5000);
    if (data.indexOf("OK") != -1 || data.indexOf("link is not") != -1) {
        return true;
    }
    return false;
}
Example #16
0
bool ESP8266::sATCWMODE(uint8_t mode)
{
    String data;
    rx_empty();
    m_puart->print("AT+CWMODE=");
    m_puart->println(mode);
    
    data = recvString("OK", "no change");
    if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
        return true;
    }
    return false;
}
int GetMoveCommand()
{
    //Parse out the move command.
    String moveCommand = slaveCommand.substring(slaveCommand.indexOf(':')+1,slaveCommand.indexOf('['));

    int MoveItemInt = moveCommand.toInt();


    if(MoveItemInt >= 0)
    {
        return MoveItemInt;
    }
    return 0;
}
Example #18
0
// # simple parsing of the responses ------------------------------
//
// find <element>X</element> and return X as a String
//
String getXMLElementContent(String input, String element)
{
    // make open and close string
    String elementOpen = "<" + element + ">";
    String elementClose = "</" + element + ">";

    // get positions of open and close
    int openPos = input.indexOf(elementOpen);
    int closePos = input.indexOf(elementClose);

    #ifdef SERIALDEBUGPARSER
        Serial.print("[INF] Input length: ");
        Serial.println(input.length());
        Serial.println("[INF] Elements:");
        Serial.println(elementOpen);
        Serial.println(elementClose);
        Serial.println("[INF] Positions:");
        Serial.println(openPos);
        Serial.println(closePos);
    #endif // SERIALDEBUG


    // verify if open and close can be found in the input
    if (openPos == -1 || closePos == -1) {
		Serial.println("[ERR] can not find element in input");
		return NULL;
	}

    // idx: starts at index of element + length of element + tags
    int idx = openPos + elementOpen.length();

    // check if length is above 0
    if (closePos - idx > 0) {
        #ifdef SERIALDEBUGPARSER
            Serial.print("[INF] Output length: ");
            Serial.println((input.substring(idx,  closePos)).length());
        #endif
        return input.substring(idx,  closePos);

    } else {
        #ifdef SERIALDEBUGPARSER
            Serial.println("[ERR] idx seems wrong");
        #endif
        return NULL;

    }

}
Example #19
0
void Configuration::begin() {
	size = computeLines();
	Serial.printf("size: %d\n", size);
	if (size > 0) {
		properties = new pair[size];
		File f = SPIFFS.open(fileName, "r");
		if (f) {
			for (int i = 0; i < size; i++) {
				String line = f.readStringUntil('\n');
				int ind = line.indexOf('=');

				if (ind != -1) {
					properties[i].key = line.substring(0, ind);
					properties[i].key.trim();
					properties[i].value = line.substring(ind + 1);
					properties[i].value.trim();
					Serial.printf("read from file: |%s=%s|\n",
							properties[i].key.c_str(),
							properties[i].value.c_str());
				}
			}
			f.close();
		}
	}
}
Example #20
0
String textToMorse(char c) {
  int index = textKey.indexOf(c);
  if (index != -1)
    return morseKey[index];
  else
    return "";
}
bool KeyValueStore::migrate() {
  if (!SPIFFS.exists(FILENAME_OLD)) {
    return true;
  }
  StaticJsonBuffer<300> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();

  File f = SPIFFS.open(FILENAME_OLD, "r");
  if (!f) {
    return false;
  }
  while(f.available()) {
    String line = f.readStringUntil('\n');
    int separator = line.indexOf("=");
    if (separator > -1) {
      String key = line.substring(0, separator);
      String value = line.substring(separator + 1);
      value.trim();
      root[key] = value;
    }
  }
  f.close();
  clear(FILENAME_JSON);
  File fJson = SPIFFS.open(FILENAME_JSON, "w");
  root.printTo(fJson);
  fJson.close();
  Serial.println("Migrated KeyValueStore to JSON:");
  root.prettyPrintTo(Serial);
  Serial.println();
  clear(FILENAME_OLD);
  return true;
}
//Function that control the specific brightness of the led conected to specific pwmpin.
//the structure of the command is pwmpin:brightness
int controlPWM(String command) {
     int index=command.indexOf(":");
     String pwmpin=command.substring(0,index);
     String val=command.substring(index+1);
     int pin=pwmpin.toInt();
     int value=val.toInt();
    if (value<256&&value>=0){
        analogWrite(pin,value);
        if (pin==10){
            EEPROMData.outputData.pwmoutput[2].pin=pin;
            EEPROMData.outputData.pwmoutput[2].value=value;
         }
        else if (pin==11){
            EEPROMData.outputData.pwmoutput[3].pin=pin;
            EEPROMData.outputData.pwmoutput[3].value=value;
        }
        else if (pin>13&&pin<18){
            EEPROMData.outputData.pwmoutput[pin-10].pin=pin;
            EEPROMData.outputData.pwmoutput[pin-10].value=value;
        }
        else if (pin<2){
            EEPROMData.outputData.pwmoutput[pin].pin=pin;
            EEPROMData.outputData.pwmoutput[pin].value=value;
        }
        writeEEPROM();
        return value;
    }
    else{
        return -1;// return -1 if the pin sended on the command is not the PWM output ones
    }
}
/*************************************************************************
//show the current connection mode(sigle or multiple)
		
		return:		string of connection mode
			0	-	sigle
			1	-	multiple

***************************************************************************/
String WIFI::showMux(void)
{
    String data;
    _cell.println("AT+CIPMUX?");  

      unsigned long start;
	start = millis();
    while (millis()-start<3000) {
       if(_cell.available()>0)
       {
       char a =_cell.read();
       data=data+a;
       }
       if (data.indexOf("OK")!=-1)
       {
           break;
       }
    }
          char head[4] = {0x0D,0x0A};   
          char tail[7] = {0x0D,0x0A,0x0D,0x0A};        
          data.replace("AT+CIPMUX?","");
          data.replace("+CIPMUX","showMux");
          data.replace("OK","");
		  data.replace(tail,"");
          data.replace(head,"");
          
          return data;
}
Example #24
0
bool WebSocketClient::readHandshake() {
    bool result = false;
    char character;
    String handshake = "", line;
    int maxAttempts = 300, attempts = 0;
    
    while(_client.available() == 0 && attempts < maxAttempts) 
    { 
        // Wifi.run();
        // Serial.println("Handshake1");
        delay(100); 
        attempts++;
    }
    
    while((line = readLine()) != "") {
        // Wifi.run();
        Serial.println("Handshake2");
        handshake += line + '\n';
    }
    
    String response = getStringTableItem(6);
    result = handshake.indexOf(response) != -1;
    
    if(!result) {
        _client.stop();
    }
    
    return result;
}
Example #25
0
boolean Minitel::isAccent(char c) {
  String accents = "áàâäéèëêíìîïóòôöúùûü";
  if (accents.indexOf(c) >=0) {
    return true; 
  }
  return false;
}
Example #26
0
bool cutBefore(String &str, const String& pat)
{
    int pos = str.indexOf(pat);
    if(pos < 0) return false;
    str.remove(0, pos);
    return true;
}
Example #27
0
File: test.cpp Project: nandai/slog
void StringTest::test01()
{
    SLOG(CLS_NAME, "test01");

    String str = "aabc";
    int32_t res;

    res = str.indexOf('b');
    SASSERT("01", (res == 2));

    res = str.indexOf("b");
    SASSERT("02", (res == 2));

    res = str.indexOf("abc");
    SASSERT("03", (res == 1));
}
Example #28
0
float GPSInterface::convert(String str, boolean dir) {
  double mm, dd;
  int point = str.indexOf('.');
  dd = str.substring(0, (point - 2)).toFloat();
  mm = str.substring(point - 2).toFloat() / 60.00;
  return (dir ? -1 : 1) * (dd + mm);
}
Example #29
0
bool cutAfter(String &str, const String& pat)
{
    int pos = str.indexOf(pat);
    if(pos < 0) return false;
    pos += pat.size();
    str.remove(pos, str.size() - pos);
    return true;
}
Example #30
0
bool ESP8266::sATCIPSTARTSingle(String type, String addr, uint32_t port)
{
    String data;
    rx_empty();
    m_puart->print("AT+CIPSTART=\"");
    m_puart->print(type);
    m_puart->print("\",\"");
    m_puart->print(addr);
    m_puart->print("\",");
    m_puart->println(port);
    
    data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
    if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
        return true;
    }
    return false;
}