Exemple #1
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;
}
Exemple #2
0
void Radioino::sendSensorsStatus()
{
	send(getInputSensorsStatus());
}