Example #1
0
// Callback for messages, arrived from MQTT server
void onMessageReceived(String topic, String message)
{
	if (topic.endsWith("Firmware"))
	{
		if (message.equals("UPDATE"))
		{
			OtaUpdate();
		}
	}
	if (topic.endsWith("Lunch"))
	{
		if (topic.equals(mqtt_client + "/Lunch"))
		{
			// My own message

		} else {
			messageSentByMe = false;
		}
		if (message.equals("ON"))
		{
			indicationState = INDICATION_LUNCH;
		}
		else
		{
			indicationState = INDICATION_CONNECTED;
		}
	}
	Serial.print(topic);
	Serial.print(":\r\n\t"); // Pretify alignment for printing
	Serial.println(message);
	WifiAccessPoint.enable(false);
}
Example #2
0
	void BeamSword::onAnimationFinish(const String&name)
	{
		if(name.equals("swing_left") || name.equals("swing_right")
		|| name.equals("swing2_left") || name.equals("swing2_right"))
		{
			active = false;
			Player*playr = getPlayer();
			if(playr!=null)
			{
				switch(playr->getPlayerDir())
				{
					case Player::LEFT:
					changeAnimation("carry_left",FORWARD);
					break;
					
					case Player::RIGHT:
					changeAnimation("carry_right",FORWARD);
					break;
				}
			}
			else
			{
				changeAnimation("normal",FORWARD);
			}
		}
	}
Example #3
0
boolean TinyGSM::isConnected(){
	print("AT+CREG?\r");
	delay(100);
	while(_serial->available()){
		String input = _serial->readStringUntil('\n');
		input.trim();
		if (input.equals("+CREG: 0,1") || input.equals("+CREG: 0,5")) return true;
	}
	return false;
}
Example #4
0
bool ESP8266WebServer::authenticate(const char * username, const char * password){
  if(hasHeader(AUTHORIZATION_HEADER)){
    String authReq = header(AUTHORIZATION_HEADER);
    if(authReq.startsWith("Basic")){
      authReq = authReq.substring(6);
      authReq.trim();
      char toencodeLen = strlen(username)+strlen(password)+1;
      char *toencode = new char[toencodeLen + 1];
      if(toencode == NULL){
        authReq = String();
        return false;
      }
      char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
      if(encoded == NULL){
        authReq = String();
        delete[] toencode;
        return false;
      }
      sprintf(toencode, "%s:%s", username, password);
      if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){
        authReq = String();
        delete[] toencode;
        delete[] encoded;
        return true;
      }
      delete[] toencode;
      delete[] encoded;
    }
    authReq = String();
  }
  return false;
}
Example #5
0
bool WebServer::authenticate(const char * username, const char * password)
{
  if(_autorization.length()>0)
  {
    String authReq = _autorization;
    if(authReq.startsWith("Basic")){
      authReq = authReq.substring(6);
      authReq.trim();
      char toencodeLen = strlen(username)+strlen(password)+1;
      char *toencode = new char[toencodeLen + 1];
      if(toencode == NULL){
        return false;
      }
      char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
      if(encoded == NULL){
        delete[] toencode;
        return false;
      }
      sprintf(toencode, "%s:%s", username, password);
      if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){
        delete[] toencode;
        delete[] encoded;
        return true;
      }
      delete[] toencode;
      delete[] encoded;
    }
  }
  return false;
}
Example #6
0
	void HeartContainer::onAnimationFinish(const String&n)
	{
		if(n.equals("sparkle"))
		{
			destroy();
		}
	}
Example #7
0
File: test.cpp Project: nandai/slog
void JsonTest::test02()
{
    SLOG(CLS_NAME, "test01");

    String str;
    Json* json1 = Json::getNewObject();

    Json* json2 = Json::getNewObject();
    json2->add("addr", "Tokyo");
    json2->add("tel", "03");
    json1->add(json2);

    Json* json3 = Json::getNewObject();
    json3->add("addr", "Osaka");
    json3->add("tel", "06");
    json1->add(json3);

    json1->serialize(&str);
    SMSG(slog::DEBUG, "%s", str.getBuffer());
    SASSERT("01", str.equals(
        "["
            "{\"addr\":\"Tokyo\",\"tel\":\"03\"},"
            "{\"addr\":\"Osaka\",\"tel\":\"06\"}"
        "]"));

    delete json1;
}
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 #9
0
void blockingRunSpeedToPosition(int direction, String axis)
{
  /*
     runSpeedToPosition is non blocking.
     You must call this as frequently as possible, but at least once per step interval,
     But we want blocking so we have to implement own loop using while
   */
   Serial.println("got "+axis);
   int steps = 1600;
   if(direction == BACKWORD) {
       steps = -steps;
   }
   ///stepper.move funtion : Set the target position relative to the current position
   /// if position is negative then anticlockwise from the current position, else clockwise from current position
   if(axis.equals("x")){
       stepperX.setCurrentPosition(0);
       stepperX.move(steps);
       while (stepperX.distanceToGo() != 0) {
           stepperX.run();
        }
    }else if (axis.equals("y")) {
        long positions[2];
        positions[0]=steps;
        positions[1]=steps;
        stepperY.setCurrentPosition(0);
        stepperZ.setCurrentPosition(0);

        steppers.moveTo(positions);
        // while (stepperY.distanceToGo()!=0 && stepperZ.distanceToGo()!=0) {
        //     steppers.run();
        // }
        steppers.runSpeedToPosition();
    }else if (axis.equals("z")) {
        long positions[2];
        positions[0]=steps;
        positions[1]=-steps;
        stepperY.setCurrentPosition(0);
        stepperZ.setCurrentPosition(0);

        steppers.moveTo(positions);
        steppers.runSpeedToPosition();
        // while (stepperY.distanceToGo()!=0 && stepperZ.distanceToGo()!=0) {
        //     steppers.run();
        // }
    }
}
Example #10
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 #11
0
File: test.cpp Project: nandai/slog
void JsonTest::test01()
{
    SLOG(CLS_NAME, "test01");

    String str;
    Json* json1 = Json::getNewObject();

    json1->serialize(&str);
    SMSG(slog::DEBUG, "%s", str.getBuffer());
    SASSERT("01", str.equals("{}"));

    json1->add("name", "printf");
    json1->serialize(&str);
    SMSG(slog::DEBUG, "%s", str.getBuffer());
    SASSERT("02", str.equals("{\"name\":\"printf\"}"));

    delete json1;
}
Example #12
0
  sp<Retval> MonPacket::parseLine(String& sLine){
      sp<Retval> retval;

      Regexp b("^[\\s]*([\\S]+):[\\s]*([\\S\\s]+)");
      if( DFW_RET(retval, b.regexp(sLine.toChars())) )
          return DFW_RETVAL_D(retval);

      String sName;
      String sTemp;
      sName.set(b.getMatch(1), b.getMatchLength(1));
      sTemp.set(b.getMatch(2), b.getMatchLength(2));

     //face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
     //eno16777736: 43582102  237978    0  495    0     0          0         0  4023838   47391    0    0    0     0       0          0
     //lo: 6879295   64596    0    0    0     0          0         0  6879295   64596    0    0    0     0       0          0

      if( sName.equals("lo") ) return NULL;

      int c = 0;
      String sVal;
      const char* p = sTemp.toChars();
      do{
          if( (*p) == '\0' ) break;
          if( ((*p)==' ') || ((*p)=='\t') ){
              p++;
              continue;
          }

          const char* b = ::strstr(p, " ");
          if( !b ) {
              sVal.set(p);
          }else{
              sVal.set(p, b-p);
          }

          p += sVal.length();

          if( N_R_BYTES == c ) {
              m_rbytes += Long::parseLong(sVal);
          }else if( N_R_PACKETS == c ) {
              m_rpackets += Long::parseLong(sVal);
          }else if( N_R_ERRS == c ) {
              m_rerrs += Long::parseLong(sVal);
          }else if( N_T_BYTES == c ) {
              m_tbytes += Long::parseLong(sVal);
          }else if( N_T_PACKETS == c ) {
              m_tpackets += Long::parseLong(sVal);
          }else if( N_T_ERRS == c ) {
              m_terrs += Long::parseLong(sVal);
          }

          c++;
      }while(true);

      return NULL;
  }
Example #13
0
  sp<Retval> MonPacket::parseTitle_l(sp<String>& s
                         , int* all, int* bytes, int* packets, int* errs)
  {
      int find = 0;
      int c = 0;
      String sVal;
      const char* p = s->toChars();
      do{
          if( (*p) == '\0' ) { break; }
          if( ((*p)==' ') || ((*p)=='\t') ){ p++; continue; }

          const char* b = ::strstr(p, " ");
          if( !b ) {
              sVal.set(p);
          }else{
              sVal.set(p, b-p);
          }

          p += sVal.length();

          //bytes    packets errs drop fifo frame compressed multicast
          //bytes    packets errs drop fifo colls carrier compressed
          if( sVal.equals("bytes") ){
              *bytes = c;
              find++;
          }else if( sVal.equals("packets") ){
              *packets = c;
              find++;
          }else if( sVal.equals("errs") ){
              *errs = c;
              find++;
          }

          c++;
      }while(true);

      if( find == 3 ){
          *all = c;
          return NULL;
      }
      return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0
                 , "Not find need format (%s)", source_path());
  }
Example #14
0
void check_serial_cmd()
{
	while (Serial.available())
	{
		delay(1);
		static String command;
		char input = Serial.read();

		if (input == '\r')
		{

		} 
		else if (input == '\n')
		{
			if (command.equals(("size")))
			{
				PTS("Schedule size: ");
				PTL(node_size());
			} else if (command.equals(("mem"))) {
				PTLS("Reading");
				for (int i = 0; i < MAX_NODE; i++) {
					schedule s = node_get(i);
					PT(i); PTS(", ");
					PT(s.day); PTS(", ");
					PT(s.hour); PTS(", ");
					PT(s.minute); PTS(", ");
					PT(s.temperature); PTL();
				}
			} else if (command.equals(("RESET"))) {
				PTLS("Resetting Memory");
				node_RESET();
			}
			command = "";
		}
		else
		{
			command.concat(input);
		}

	}
}
Example #15
0
	bool AssetManager::alreadyStoredImage(const String&imgName)
	{
		int total = ImageNames.size();
		for(int i=0; i<total; i++)
		{
			if(imgName.equals(ImageNames.get(i)))
			{
				return true;
			}
		}
		return false;
	}
Example #16
0
	bool AssetManager::alreadyStoredFont(const String&fontName)
	{
		int total = FontNames.size();
		for(int i=0; i<total; i++)
		{
			if(fontName.equals(FontNames.get(i)))
			{
				return true;
			}
		}
		return false;
	}
void JsonStreamingParser::endNull() {
    buffer[bufferPos] = '\0';
    String value = String(buffer);
    if (value.equals("null")) {
      myListener->value("null");
    } else {
      // throw new ParsingError($this->_line_number, $this->_char_number,
      // "Expected 'true'. Got: ".$true);
    }
    bufferPos = 0;
    state = STATE_AFTER_VALUE;
  }
Example #18
0
	bool AnimationManager::contains(const String&animName)
	{
		for(int i=0; i<totalAnimations; i++)
		{
			Animation*cAnim = animations.get(i);
			if(animName.equals(cAnim->name))
			{
				return true;
			}
		}
		return false;
	}
Example #19
0
bool GlobalPreferences_installedApps_contains(const char* appName)
{
	String appNameString = appName;
	for(int i=0; i<installedApps.size(); i++)
	{
		if(appNameString.equals(installedApps.get(i)))
		{
			return true;
		}
	}
	return false;
}
Example #20
0
void GlobalPreferences_installedApps_remove(const char* appName)
{
	String appNameString = appName;
	for(int i=0; i<installedApps.size(); i++)
	{
		if(appNameString.equals(installedApps.get(i)))
		{
			installedApps.remove(i);
			return;
		}
	}
}
Example #21
0
File: test.cpp Project: nandai/slog
void JsonTest::test04()
{
    SLOG(CLS_NAME, "test04");

    String str;
    Json* json1 = Json::getNewObject();

    json1->add("id", 1);
    json1->serialize(&str);
    SMSG(slog::DEBUG, "%s", str.getBuffer());
    SASSERT("01", str.equals("{\"id\":1}"));
}
Example #22
0
void GlobalPreferences_installedApps_add(const char* appName)
{
	String appNameString = appName;
	for(int i=0; i<installedApps.size(); i++)
	{
		if(appNameString.equals(installedApps.get(i)))
		{
			return;
		}
	}
	installedApps.add(appNameString);
	GlobalPreferences_save();
}
void parseCommand(String command)
{
    if (command.equals("help") || command.equals("h") || command.equals("?"))
    {
        Serial.println(COMMAND_HELP);
    }
    else if (command.equals("led stop"))
    {
        gLedBlinkActive = false;
        digitalWrite(LED_BUILTIN, LOW);
    }
    else if (command.equals("led start"))
    {
        gLedBlinkActive = true;
    }
    // No command found
    else
    {
        Serial.println(COMMAND_ERROR_NO_COMMAND_FOUND);
        Serial.println(COMMAND_HELP);
    }
}
Example #24
0
	void AssetManager::unloadImage(const String&imgName)
	{
		int total = ImageNames.size();
		for(int i=0; i<total; i++)
		{
			if(imgName.equals(ImageNames.get(i)))
			{
				delete Images[i];
				Images.remove(i);
				ImageNames.remove(i);
				return;
			}
		}
	}
Example #25
0
	bool AnimationManager::remove(const String&animName)
	{
		for(int i=(totalAnimations-1); i>=0; i--)
		{
			Animation*cAnim = animations.get(i);
			if(animName.equals(cAnim->name))
			{
				animations.remove(i);
				return true;
			}
		}
		Console::WriteLine((String)"Error: animation " + animName + (String)" could not be removed");
		return false;
	}
Example #26
0
	void AssetManager::unloadFont(const String&fontName)
	{
		int total = FontNames.size();
		for(int i=0; i<total; i++)
		{
			if(fontName.equals(FontNames.get(i)))
			{
				delete Fonts[i];
				Fonts.remove(i);
				FontNames.remove(i);
				return;
			}
		}
	}
Example #27
0
File: test.cpp Project: nandai/slog
void JsonTest::test03()
{
    SLOG(CLS_NAME, "test03");
    String str;

    Json* json1 = Json::getNewObject();
    Json* json2 = Json::getNewObject("messages");

    json1->add(json2);
    json1->add("kind", "0003");

    json1->serialize(&str);
    SMSG(slog::DEBUG, "%s", str.getBuffer());
    SASSERT("01", str.equals("{\"messages\":[],\"kind\":\"0003\"}"));

    delete json1;
}
Example #28
0
unsigned int MeshishNode::_getNodeType(const AccessPoint& ap)
{
  String prefix = ap.ssid.substring(0, _ssidPrefix.length());

  if (prefix.equals(_ssidPrefix))
  {
    if (ap.ssid.substring(_ssidPrefix.length(), _ssidPrefix.length() + 3).equals("_1_"))
    {
      return NODE_PRIMARY;
    }
    else if (ap.ssid.substring(_ssidPrefix.length(), _ssidPrefix.length() + 3).equals("_0_"))
    {
      return NODE_SECONDARY;
    }
  }

  return NODE_NONE;
}
bool ESP_MQTTLogger::_authenticate(){

  if(_server->hasHeader(MQTT_AUTHORIZATION_HEADER)) {
    String authReq = _server->header(MQTT_AUTHORIZATION_HEADER);

#ifdef MQTT_LOGGER_DEBUG
    DEBUG_OUTPUT.print("authReq: ");
    DEBUG_OUTPUT.println(authReq);
#endif

    if(authReq.startsWith("Token")){
      authReq = authReq.substring(6);
      authReq.trim();

      if (authReq.equals(_token)){
        return true;
      }
    }
  }

  return false;
}
void
GenericHDBRepository::deleteNameSpace(const String& key)
{
    throwIfNotOpen();
    if (key.equals("root"))
    {
        OW_THROWCIMMSG(CIMException::FAILED,
                       "cannot delete root namespace");
    }
    HDBHandleLock hdl(this, getHandle());
    HDBNode node = hdl->getNode(key);
    if (node)
    {
        if (!node.areAllFlagsOn(HDBNSNODE_FLAG))
        {
            OW_THROW(IOException, "logic error. deleting non-namespace node");
        }
        hdl->removeNode(node);
    }
    else
    {
        OW_THROWCIMMSG(CIMException::FAILED, Format("Unable to delete namespace %1", key).c_str());
    }
}