Esempio n. 1
0
byte Radioino::receiveCommand()
{
	// Check the setup mode command
	if (digitalRead(_setupButtonPin)==HIGH && !_setupMode)
	{	
		_setupMode = true;
		_previousTime = 0;
		_setupModeCount = 0;
	}
	if (_setupMode)
	{
		// check to see if it's time to blink the LED; that is, if the 
		// difference between the current time and last time you blinked 
		// the LED is bigger than the interval at which you want to 
		// blink the LED.
		unsigned long currentTime = millis();
		if(currentTime - _previousTime > RADIOINO_SETUP_LED_BLINK_MS) {
			// save the last time you blinked the LED 
			_previousTime = currentTime;   
			setActivityLedState(!_activityLedState);
			_setupModeCount++;
		}
		
		// Exit the setup mode
		if (_setupModeCount > RADIOINO_SETUP_ATTEMPTS)
		{
			_setupMode = false;
			setActivityLedState(LOW);
		}
	}
	
	//Wait for a new command
	_commandResult = RADIOINO_NO_COMMAND;
	if (Serial.available() > 0) {
		if (receive()) {
			if (execute())
			{
				// Build the response message
				beginResponse(true);
				// Add the sensors status
				sendSensorsStatus();   
				_commandResult = RADIOINO_COMMAND_OK;
			}
			else {
				// Build the error response message
				beginResponse(false);
				_commandResult = RADIOINO_COMMAND_ERROR;
			}
			// wait for another command
			resetCommand();
		}
	}
	// end activity
	setActivityLedState(LOW);  
	
	return _commandResult;
}
Esempio n. 2
0
byte IOToaster::receiveCommand()
{
	if (_setupMode)
	{
		// check to see if it's time to blink the LED; that is, if the 
		// difference between the current time and last time you blinked 
		// the LED is bigger than the interval at which you want to 
		// blink the LED.
		unsigned long currentTime = millis();
		if (currentTime - _previousTime > IOTOASTER_SETUP_LED_BLINK_MS) {
			// save the last time you blinked the LED 
			_previousTime = currentTime;

			// if the LED is off turn it on and vice-versa:
			if (_activityLedState == LOW)
				setActivityLedState(HIGH);
			else setActivityLedState(LOW);
		}
	}

	//Wait for a new command
	_commandResult = IOTOASTER_NO_COMMAND;
	if (Serial.available() > 0) {
		if (receive()) {
			if (_command.startsWith("+IPD")) // Check for data sent from the server
			{
				_command = _command.substring(_command.lastIndexOf(':') + 1);
				_customResponse = "";
				if (execute())
				{
					// Build the response message
					beginResponse(true);
					// Add the sensors status
					send(getInputSensorsStatus());
					_commandResult = IOTOASTER_COMMAND_OK;
				}
				else {
					// Build the error response message
					beginResponse(false);
					_commandResult = IOTOASTER_COMMAND_ERROR;
				}
			}
			// wait for another command
			resetCommand();
		}
	}

	return _commandResult;
}