Example #1
0
String ESP8266WebServer::urlDecode(const String& text)
{
	String decoded = "";
	char temp[] = "0x00";
	unsigned int len = text.length();
	unsigned int i = 0;
	while (i < len)
	{
		char decodedChar;
		char encodedChar = text.charAt(i++);
		if ((encodedChar == '%') && (i + 1 < len))
		{
			temp[2] = text.charAt(i++);
			temp[3] = text.charAt(i++);

			decodedChar = strtol(temp, NULL, 16);
		}
		else {
			if (encodedChar == '+')
			{
				decodedChar = ' ';
			}
			else {
				decodedChar = encodedChar;  // normal ascii char
			}
		}
		decoded += decodedChar;
	}
	return decoded;
}
Example #2
0
Variant f_range(CVarRef low, CVarRef high, CVarRef step /* = 1 */) {
  bool is_step_double = false;
  double dstep = 1.0;
  if (step.isDouble()) {
    dstep = step.toDouble();
    is_step_double = true;
  } else if (step.isString()) {
    int64_t sn;
    double sd;
    DataType stype = step.toString()->isNumericWithVal(sn, sd, 0);
    if (stype == KindOfDouble) {
      is_step_double = true;
      dstep = sd;
    } else if (stype == KindOfInt64) {
      dstep = (double)sn;
    } else {
      dstep = step.toDouble();
    }
  } else {
    dstep = step.toDouble();
  }
  /* We only want positive step values. */
  if (dstep < 0.0) dstep *= -1;
  if (low.isString() && high.isString()) {
    String slow = low.toString();
    String shigh = high.toString();
    if (slow.size() >= 1 && shigh.size() >=1) {
      int64_t n1, n2;
      double d1, d2;
      DataType type1 = slow->isNumericWithVal(n1, d1, 0);
      DataType type2 = shigh->isNumericWithVal(n2, d2, 0);
      if (type1 == KindOfDouble || type2 == KindOfDouble || is_step_double) {
        if (type1 != KindOfDouble) d1 = slow.toDouble();
        if (type2 != KindOfDouble) d2 = shigh.toDouble();
        return ArrayUtil::Range(d1, d2, dstep);
      }

      int64_t lstep = (int64_t) dstep;
      if (type1 == KindOfInt64 || type2 == KindOfInt64) {
        if (type1 != KindOfInt64) n1 = slow.toInt64();
        if (type2 != KindOfInt64) n2 = shigh.toInt64();
        return ArrayUtil::Range((double)n1, (double)n2, lstep);
      }

      return ArrayUtil::Range((unsigned char)slow.charAt(0),
                              (unsigned char)shigh.charAt(0), lstep);
    }
  }

  if (low.is(KindOfDouble) || high.is(KindOfDouble) || is_step_double) {
    return ArrayUtil::Range(low.toDouble(), high.toDouble(), dstep);
  }

  int64_t lstep = (int64_t) dstep;
  return ArrayUtil::Range(low.toDouble(), high.toDouble(), lstep);
}
Example #3
0
byte Convert::toHex(String input)
{
  input.toUpperCase();
  byte result = 0x00;
  //input checking
  if(input.length()==4) input = input.substring(2);
  else if(input.length()==3||input.length()>4) return 0x00;
  //
  result=this->value(input.charAt(0)); //first hex
  result=result<<4; //bitshift 4 places to the left
  result+=this->value(input.charAt(1)); //second hex
  return result;
}
Example #4
0
/*******************************************************************************
 * Function Name  : tinkerDigitalRead
 * Description    : Reads the digital value of a given pin
 * Input          : Pin
 * Output         : None.
 * Return         : Value of the pin (0 or 1) in INT type
                    Returns a negative number on failure
 *******************************************************************************/
int tinkerDigitalRead(String pin)
{
    //convert ascii to integer
    int pinNumber = pin.charAt(1) - '0';
    //Sanity check to see if the pin numbers are within limits
    if (pinNumber < 0 || pinNumber > 7) return -1;

    if(pin.startsWith("D"))
    {
        pinMode(pinNumber, INPUT_PULLDOWN);
        return digitalRead(pinNumber);
    }
    else if (pin.startsWith("A"))
    {
        pinMode(pinNumber+10, INPUT_PULLDOWN);
        return digitalRead(pinNumber+10);
    }
#if Wiring_Cellular
    else if (pin.startsWith("B"))
    {
        if (pinNumber > 5) return -3;
        pinMode(pinNumber+24, INPUT_PULLDOWN);
        return digitalRead(pinNumber+24);
    }
    else if (pin.startsWith("C"))
    {
        if (pinNumber > 5) return -4;
        pinMode(pinNumber+30, INPUT_PULLDOWN);
        return digitalRead(pinNumber+30);
    }
#endif
    return -2;
}
 char  VirtuinoEthernet_WebServer::getCommandType(String aCommand){
   char commandType= aCommand.charAt(0);
   if (!(commandType == 'I' || commandType == 'Q' || commandType == 'D' ||commandType == 'A' ||commandType == 'O' || commandType == 'V' || commandType == 'C')){
     commandType='E'; //error  command
   }
   return commandType;
 }
 void render() {
   translate(width/2, height/2);
   steps += 5;          
   if (steps > production.length()) {
     steps = production.length();
   }
   for (int i = 0; i < steps; i++) {
     char step = production.charAt(i);
     if (step == 'F') {
       rect(0, 0, -drawLength, -drawLength);
       noFill();
       translate(0, -drawLength);
     } 
     else if (step == '+') {
       rotate(theta);
     } 
     else if (step == '-') {
       rotate(-theta);
     } 
     else if (step == '[') {
       pushMatrix();
     } 
     else if (step == ']') {
       popMatrix();            
     }
   }
 }
Example #7
0
void Morse::emitWord(String word) {
  int len = word.length();
  int i, ci;
  for (i = 0; i < len; i++) {

    String code = textToMorse(word.charAt(i));
    int codeLen = code.length();
    for (ci = 0; ci < codeLen; ci++) {

      if (code[ci] == '.') {
        dot();
      } else {
        dash();
      }
    }

    // morse code states there should be a 3 time unit pause between
    // characters
    // 2 here and one at the end of dot/dash
    delay(_timeUnit * 2);
  }
  // morse code states there should be a 7 time unit pause between words
  // 4 here and 3 above
  delay(_timeUnit * 4);
}
void PusherClient::getAuthString(const String& channel, String& auth)
{
	Sha256Class sha256;
	
	//Sha init with secret key
	{
		String secret;
		getPusherInfoItem(2, secret);
		sha256.initHmac((uint8_t*)&secret[0], secret.length());
	}
	
	//Set the data to encrypt
	{
		String text;
		text.reserve(_socketid.length() + 1 + channel.length());
		text = _socketid;
		text += ':';
		text += channel;
		sha256.print(text);
	}
	
	uint8_t* result = sha256.resultHmac();
	
	String hexChars;
	getStringTableItem(19, hexChars);
	
	auth.reserve(21 /*key*/ + 1 + 64 /*sha256*/);	
	getPusherInfoItem(1, auth); //key
	auth += ':';	
	for (int i=0; i<32; i++)
	{
		auth += hexChars.charAt(result[i]>>4);
		auth += hexChars.charAt(result[i]&0xf);
	}
}
Example #9
0
/*******************************************************************************
 * Function Name  : tinkerDigitalWrite
 * Description    : Sets the specified pin HIGH or LOW
 * Input          : Pin and value
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int tinkerDigitalWrite(String command)
{
    bool value = 0;
    //convert ascii to integer
    int pinNumber = command.charAt(1) - '0';
    //Sanity check to see if the pin numbers are within limits
    if (pinNumber< 0 || pinNumber >7) return -1;

    if(command.substring(3,7) == "HIGH") value = 1;
    else if(command.substring(3,6) == "LOW") value = 0;
    else return -2;

    if(command.startsWith("D"))
    {
        pinMode(pinNumber, OUTPUT);
        digitalWrite(pinNumber, value);
        return 1;
    }
    else if(command.startsWith("A"))
    {
        pinMode(pinNumber+10, OUTPUT);
        digitalWrite(pinNumber+10, value);
        return 1;
    }
    else return -3;
}
Example #10
0
 String runString(CppiaCtx *ctx)
 {
    String val = strVal->runString(ctx);
    BCR_CHECK;
    int idx = a0->runInt(ctx);
    BCR_CHECK;
    return val.charAt(idx);
 }
Example #11
0
void Minitel::text(String s, int orientation) {
  for (int i=0; i<s.length(); i++) {
    char c = s.charAt(i);
    boolean indent = false;
    if (isAccent(c)) {
      i+=1; // chars with accents take 2 array indexes
      c = s.charAt(i);
      indent = printAccentChar(c);
    }
    else {
      indent = textChar(c);
    }
    if (indent && orientation == VERTICAL) {
      moveCursor(LEFT);
      moveCursor(DOWN);
    }
  }
}
Example #12
0
boolean Clock::parseDate(String t)
{ 
  // dd/mm/yyyy
  int d;
  int m;
  int y;
  if (t.length() != 10) return false;
  if (t.charAt(2) != '/' || t.charAt(5) != '/') return false;
  d=t.substring(0,2).toInt();
  m=t.substring(3,5).toInt();
  y=t.substring(6,10).toInt();
  if (d ==0 || m==0 || y==0) return false;

  //Todo adjust for local time?
  set(y,m,d,hour(),minute(),second());

  return true;
}
Example #13
0
/**
 * Precondition: m_originalURL and m_queryString are set
 * Postcondition: Output is false and we are redirecting OR
 *  m_rewrittenURL is set and m_queryString is updated if needed
 */
bool RequestURI::rewriteURL(const VirtualHost *vhost, Transport *transport,
                            const std::string &pathTranslation,
                            const std::string &sourceRoot) {
    bool qsa = false;
    int redirect = 0;
    std::string host = transport->getHeader("host");
    m_rewrittenURL = m_originalURL;
    if (vhost->rewriteURL(host, m_rewrittenURL, qsa, redirect)) {
        m_rewritten = true;
        if (qsa && !m_queryString.empty()) {
            m_rewrittenURL += (m_rewrittenURL.find('?') < 0) ? "?" : "&";
            m_rewrittenURL += m_queryString;
        }
        if (redirect) {
            if (m_rewrittenURL.substr(0, 7) != s_http &&
                    m_rewrittenURL.substr(0, 8) != s_https) {
                PrependSlash(m_rewrittenURL);
            }
            transport->redirect(m_rewrittenURL.c_str(), redirect, "rewriteURL");
            return false;
        }
        splitURL(m_rewrittenURL, m_rewrittenURL, m_queryString);
    }
    m_rewrittenURL = String(
                         Util::canonicalize(m_rewrittenURL.c_str(), m_rewrittenURL.size()),
                         AttachString);
    if (!m_rewritten && m_rewrittenURL.charAt(0) == '/') {
        // A un-rewritten URL is always relative, so remove prepending /
        m_rewrittenURL = m_rewrittenURL.substr(1);
    }

    // If the URL refers to a folder but does not end
    // with a slash, then we need to redictect
    String url = m_rewrittenURL;
    if (!url.empty() &&
            url.charAt(url.length() - 1) != '/') {
        if (virtualFolderExists(vhost, sourceRoot, pathTranslation, url)) {
            url += "/";
            m_rewritten = true;
            String queryStr;
            m_rewrittenURL = m_originalURL;
            m_rewrittenURL += "/";
            if (!m_queryString.empty()) {
                m_rewrittenURL += "?";
                m_rewrittenURL += m_queryString;
            }
            if (m_rewrittenURL.substr(0, 7) != s_http &&
                    m_rewrittenURL.substr(0, 8) != s_https) {
                PrependSlash(m_rewrittenURL);
            }
            transport->redirect(m_rewrittenURL.c_str(), 301, "rewriteURL");
            return false;
        }
    }

    return true;
}
Example #14
0
long Convert::toInt(String input)
{
  boolean negative = false;
  long result = 0;
  //if number negative
  if(input.charAt(0) == 45)
  {
    input = input.substring(1);
    negative = true;
  }
  
  for (int i=0; i<input.length(); i++)
  {
    result = (result*10) + this->value(input.charAt(i));
  }
  if(negative) result*=-1;
  return result;
}
Example #15
0
void InternetButton::playNote(String note, int duration){
    int noteNum = 0;
    int octave = 5;
    int freq = 256;
    
     //if(9 - int(command.charAt(1)) != null){
    char octavo[5];
    String tempString = note.substring(1,2);
    tempString.toCharArray(octavo,5);
    octave = atoi(octavo);
    //}
    
    if(duration != 0){
        duration = 1000/duration;
    }
    
    switch(note.charAt(0)){
        case 'C':
            noteNum = 0;
            break;
        case 'D':
            noteNum = 2;
            break;
        case 'E':
            noteNum = 4;
            break;
        case 'F':
            noteNum = 5;
            break;
        case 'G':
            noteNum = 7;
            break;
        case 'A':
            noteNum = 9;
            break;
        case 'B':
            noteNum = 11;
            break;
        case 'R':          // Rest note
            octave = -1;
            break;
        default:
            break;
            //return -1;
    }
    
    // based on equation at http://www.phy.mtu.edu/~suits/NoteFreqCalcs.html and the Verdi tuning
    // fn = f0*(2^1/12)^n where n = number of half-steps from the reference frequency f0
    freq = float(256*pow(1.05946,(     12.0*(octave-4)        +noteNum)));
    //          C4^  (2^1/12)^    12 half-steps in an octave      ^how many extra half-steps within that octave, 0 for a C
    
    tone(D2,int(freq),duration);
    delay(duration);
    noTone(D2);
    //return freq;
}
Example #16
0
bool TheThingsUno::sendCommand(String cmd, String value, int waitTime) {
  debugPrintLn("Sending: " + cmd + " with value " + value);

  modemStream->print(cmd + " ");
  for (int i = 0; i < value.length(); i++)
    modemStream->print(String(value.charAt(i), HEX));
  modemStream->println();

  return waitForOK(waitTime);
}
Example #17
0
String HexString::Encode(const String& str){
	char tmp[3] = { 0 };
	String ret;
	for (int i = 0; i < str.length(); i++) {
		unsigned char c = str.charAt(i);
		sprintf(tmp, "%02x", c);
		ret += tmp;
	}

	return ret;
}
 int  VirtuinoEthernet_WebServer::getCommandPin(String aCommand){
   char p1= aCommand.charAt(1);
   char p2= aCommand.charAt(2);
   String s="-1";
   if (isDigit(p1) && isDigit(p2)) {
      s="";
      s.concat(p1);
      s.concat(p2);
   }
    return s.toInt();
 }
Example #19
0
   hx::Object *runObject(CppiaCtx *ctx)
   {
      String val = strVal->runString(ctx);
      BCR_CHECK;
      int idx = a0->runInt(ctx);
      BCR_CHECK;

      if (CODE)
         return val.charCodeAt(idx).mPtr;
      else
         return Dynamic(val.charAt(idx)).mPtr;
   }
void PusherClient::parseMessageMember(const String& message, const String& name, String& value)
{
	//name must be in the "name" format
	
	int memberNameStart = message.indexOf(name);
    if (memberNameStart == -1)
	{
		value = "";
		return;
	}		
		
	int memberDataStart = memberNameStart + name.length();
    
    char currentCharacter;
    do {
        memberDataStart++;
        currentCharacter = message.charAt(memberDataStart);
    } while (currentCharacter == ' ' || currentCharacter == ':' || currentCharacter == '\"');
    	
	int memberDataEnd = memberDataStart;
    bool isString = message.charAt(memberDataStart-1) == '\"';
    if (!isString) {
        do {
            memberDataEnd++;
            currentCharacter = message.charAt(memberDataEnd);
        } while (currentCharacter != ' ' && currentCharacter != ',');
    }
    else {
        char previousCharacter;
        currentCharacter = ' ';
        do {
            memberDataEnd++;
            previousCharacter = currentCharacter;
            currentCharacter = message.charAt(memberDataEnd);
        } while (currentCharacter != '"' || previousCharacter == '\\');
    }
    	
	value = message.substring(memberDataStart, memberDataEnd);
    value.replace("\\\"", "\"");
}
Example #21
0
//void (*resetFunc)(void) = 0;
//void WaterSensorWire::CheckConnection() {
////Serial.println(millis() - _lastReqReceived);
////Serial.println(millis() - _lastReqReceived > 180000);
//if(millis() - _lastReqReceived > 180000) { //check every 3 minute. 180000
//Serial.println(F("Wire Connection Lost Reseting.."));
//delay(1000);
////_lastReqReceived = millis();
//wdt_reset();
//resetFunc();
//}
//}
String ROTankWire::SplitString(String data, char separator, int index) {
    int found = 0;
    int strIndex[] = {0, -1};
    int maxIndex = data.length() - 1;
    for(int i = 0; i <= maxIndex && found <= index; i++) {
        if(data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i + 1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
Example #22
0
boolean Clock::parseTime(String t)
{
  int h;
  int m;
  int s;
  s=0;
  if (t.length() != 5 && t.length() != 8) return false;
  if (t.charAt(2) != ':') return false;
  h=t.substring(0,2).toInt();
  if (h>23) return false;
  m=t.substring(3,5).toInt();
  if (m>59) return false;
  if (t.length() == 8) {
    if (t.charAt(5) != ':') return false;
    s = t.substring(6,8).toInt();
  }
  
  //Todo adjust for local time?
  set(year(),month(),day(),h,m,s);

  return true;
}
void EvalObjectData::o_setArray(CArrRef props) {
    for (ArrayIter it(props); !it.end(); it.next()) {
        String k = it.first();
        if (!k.empty() && k.charAt(0) == '\0') {
            int subLen = k.find('\0', 1) + 1;
            String cls = k.substr(1, subLen - 2);
            String key = k.substr(subLen);
            if (cls == "*") cls = o_getClassName();
            props->load(k, o_lval(key, Variant(), cls));
        }
    }
    DynamicObjectData::o_setArray(props);
}
Example #24
0
bool ESP8266::sATCIPSENDSingle(String &str)
{
    rx_empty();
    m_puart->print("AT+CIPSEND=");
    m_puart->println(str.length());
    if (recvFind(">", 5000)) {
        rx_empty();
        for (uint32_t i = 0; i < str.length(); i++) {
            m_puart->write(str.charAt(i));
        }
        return recvFind("SEND OK", 10000);
    }
    return false;
}
Example #25
0
int ledControl(String command)
{
   int state = 0;
   //find out the pin number and convert the ascii to integer
   int pinNumber = (command.charAt(1) - '0') - 1;
   //Sanity check to see if the pin numbers are within limits
   if (pinNumber < 0 || pinNumber > 1) return -1;
   // find out the state of the led
   if(command.substring(3,7) == "HIGH") state = 1;
   else if(command.substring(3,6) == "LOW") state = 0;
   else return -1;
   // write to the appropriate pin
   digitalWrite(pinNumber, state);
   return 1;
}
Example #26
0
float Convert::toFloat(String var)
{
  long dot = var.indexOf(".");
  boolean negative = false;
  float fpoint = 1;
  float result;
  
  if (dot == -1)
  {
    dot = var.length();
  }
  
  //if number negative
  if (var.charAt(0) == 45)
  {
    negative = true;
    var = var.substring(1);
    dot--;
  }
  //convert  value
  result = toInt(var.substring(0,dot));
  for(int i = dot+1; i< var.length(); i++)
  {
    fpoint *= 0.1;
    result = result + (this->value(var.charAt(i))*fpoint);
  }
  
  //fix negative number
  if(negative)
  {
    result *=-1;
  }
  
  return result;
  
}
Example #27
0
void LCD_LAUNCHPAD::displayText(String s, char pos)
{
    int length = s.length();
    int i;
    for (i=0; i<pos; i++)
    {
        showChar(' ', i);
	}
    for (i=pos; i<length; i++)
    {
        showChar(s.charAt(i-pos), i);
    }


}
// command format r1,ON or r1,OFF or r1,SWITCH
int relayControl(String command)
{
  // parse the relay number
  int relayNumber = command.charAt(1) - '0';
  // do a sanity check
  if (relayNumber < 1 || relayNumber > 4) return -1;

  // find out the state of the relay
  if (command.substring(3,5) == "ON") relay[relayNumber - 1].on();
  else if (command.substring(3,6) == "OFF") relay[relayNumber - 1].off();
  else if (command.substring(3,9) == "SWITCH")  relay[relayNumber - 1].toggle();
  else if (command.substring(3,8) == "PULSE")  relay[relayNumber - 1].pulse();
  else return -1;

  return 1;
}
Example #29
0
int main() {

	String foo = newString("This is FOO!");
	foo = foo.insertCharAt(&foo,'a',foo.length(&foo) - 1);
	foo.printString(&foo);


	foo = foo.substring(&foo,8,10);
	foo.printString(&foo);

	String bar = newString(" BAR");
	foo = foo.concat(&foo,&bar);
	foo.printString(&foo);

	StringArr foobar = split(&foo, " ");
	printf("%s\n",foobar[0]);
	printf("%s\n",foobar[1]);

	foo = foo.toLowerCase(&foo);
	bar = bar.toLowerCase(&bar);
	bar = bar.removeSpaces(&bar);
	foo.printString(&foo);
	bar.printString(&bar);

	if(foo.equals(&foo,&bar))
		printf("Same!\n");
	else
		printf("Not the same!\n");

	bar = newString("foo");

	if(foo.equals(&foo,&bar))
		printf("Same!\n");
	else
		printf("Not the same!\n");

	foo = foo.reverse(&foo);
	foo.printString(&foo);

	printf("%c\n",foo.charAt(&foo,1));

	bar = newString("bar");
	bar = bar.toUpperCase(&bar);
	printString(&bar);

}
Example #30
0
/*******************************************************************************
 * Function Name  : tinkerAnalogRead
 * Description    : Reads the analog value of a pin
 * Input          : Pin
 * Output         : None.
 * Return         : Returns the analog value in INT type (0 to 4095)
                    Returns a negative number on failure
 *******************************************************************************/
int tinkerAnalogRead(String pin)
{
    //convert ascii to integer
    int pinNumber = pin.charAt(1) - '0';
    //Sanity check to see if the pin numbers are within limits
    if (pinNumber< 0 || pinNumber >7) return -1;

    if(pin.startsWith("D"))
    {
        return -3;
    }
    else if (pin.startsWith("A"))
    {
        return analogRead(pinNumber+10);
    }
    return -2;
}