示例#1
0
/*** FUNCTION CODE ***/
int main(int argc, char *argv[]) {
    //Setup Signal handler and atexit functions
	signal(SIGINT, INThandler);                     //Interrupts (calls INThandler) when Ctrl+c (?)
    COM1 = open_serialport("/dev/ttyUSB0",500000); //Open USB port
    Time_struct Curr_time;                          //Create time structure
    Curr_time = get_time();                         //Fill it with current time
    char fname[26];                                 //Create space for filename
    sprintf(fname, "%d-%d-%d-%d:%d:%d:%d.csv", Curr_time.year, Curr_time.month, Curr_time.day, Curr_time.hour, Curr_time.minute, Curr_time.second, Curr_time.msecond); //Create filename (date, time)
    fp = fopen(fname,"w");                          //Open file
    struct sockaddr_in outsock;
    int s_out_sensordata, slen = sizeof(struct sockaddr_in);
    initClientSocket(IMU_PORT, &s_out_sensordata, OPC_IP, &outsock);
    //initClientSocket(65100, &s_out_sensordata, "10.0.0.10", &outsock); //fakeclient
    sensor_data data;
    initBuffer();
    while(running) {
        data = receiveSensorData();
        writeToBuffer(&data);
        if (processData(&data))
            sendSensorData(&data, s_out_sensordata, outsock, slen);
    }
    //At end by Ctrl+c
    printf("Fin\n");
    fclose(fp);                                     //Close file
    return 0;
}
void loop()
{
 //loop variables
  
  if(sensorUpdateReady())
  {
   sensorVal=GetSensorData();
   refreshSensorArray(sensorVal);
   lowestSensorVal=getLowestSensorVal(sensorVal);
   sendVal= map(lowestSensorVal, SENSOR_MIN, SENSOR_MAX, 0, 255); 
   rangedSensorVal = map(sensorVal, SENSOR_MIN, SENSOR_MAX, STROBE_MIN, STROBE_MAX);
   strobeInterval= rangedSensorVal;
   //printSensorData (rangedSensorVal);
   Serial.println("");
   sendSensorData (sensorVal);    
  }
  
  if (lowestSensorVal < threshold)
  {
    digitalWrite(relayPin, HIGH);
    Serial.print('H');
  }
  
  if (lowestSensorVal > threshold)
  {
    digitalWrite(relayPin, LOW);
    Serial.print('L');
  }
  
  delay(loopDelay);
}
示例#3
0
void run()
{
    ADC_SAR_Seq_1_Start();
    ADC_SAR_Seq_1_StartConvert();

    initPSoCWiFi(SSID,PASS,DevKitIP);
    
    for(;;)
    {
        struct updateParameters values = getValues();     

        struct responses received = sendSensorData(values);

        ID = received.ID;
        wantedMoisture = received.moisture;
        wantedRotate = received.rotate;
        
        if(wantedMoisture >= values.currentMoisture)
        {
            start();
            CyDelay(1000);
            stop();
        }
        
        rotate(wantedRotate);
        
        CyDelay(6000); //10 min delay
    }
}
示例#4
0
bool yarp::dev::OpenNI2DeviceDriverServer::updateInterface() {

    // update sensor dataoniPlayback
    skeleton->updateSensor();

    // send sensor data to ports
    if(withOpenPorts) {
        sendSensorData();
    }
    return true;
}
void loop()
{
 //loop variables
  
   sensorVal=GetSensorData();
   refreshSensorArray(sensorVal);
   lowestSensorVal=getLowestSensorVal(sensorVal);
   sendVal= map(lowestSensorVal, SENSOR_MIN, SENSOR_MAX, 0, 255);
   rangedSensorVal = map(sendVal, SENSOR_MIN, SENSOR_MAX, STROBE_MIN, STROBE_MAX);
   strobeInterval= rangedSensorVal;
    //printSensorData (rangedSensorVal);
   Serial.println("");
   sendSensorData (sensorVal);

  if (strobeUpdateReady())
  {
    digitalWrite(relayPin, strobeVal);
  }
  //delay(loopDelay);
  //printSensorData(1);
}
void loop()
{
 //loop variables
  
  if(sensorUpdateReady())
  {
   sensorVal=GetSensorData();
   refreshSensorArray(sensorVal);
   lowestSensorVal=getLowestSensorVal(sensorVal);
   //sendVal= map(lowestSensorVal, SENSOR_MIN, SENSOR_MAX, 0, 255); 
   rangedSensorVal = map(sensorVal, SENSOR_MIN, SENSOR_MAX, STROBE_MIN, STROBE_MAX);
   strobeInterval= rangedSensorVal;
    //printSensorData (rangedSensorVal);
   Serial.println("");
   sendSensorData (lowestSensorVal);    
  }
  
  if (strobeUpdateReady() && lowestSensorVal < threshold)
  {
    digitalWrite(relayPin, strobeVal);
    Serial.print('H');
  }else{
  {
    //digitalWrite(relayPin, LOW);
    Serial.print('L');
  }
  
  //delay(150);
  
    //if (strobeVal == HIGH)
    //{
      //offcounter++;
      //if (offcounter > 100)
      //{
      //digitalWrite(relayPin, LOW);
      //offcounter = 0;
      //}
    //}
  }
}
示例#7
0
文件: Robot.cpp 项目: unix8net/Robot
//处理编队时连接前方和后方机器人
void Robot::processSensorData()
{
	while(true)
	{
		//PRINT("信号灯等待");
		//如果前边机器人未连接
		if(semaPhore->Wait() == 0)
		{
			//网络接通
			if(semaphoreFlag == 0)
			{
				#ifdef  ROBOT_SENSOR_DATA_DELAY_SEND
				if(consoleIsConnected)
				{
					PRINT("控制台连接,正在发送保存的数据");
					//准备发送传感器数据,所以现在不能写
					fsIsUseToWrite= false;
					sendSensorData();
					emptyData();
					PRINT("发送保存的数据完成");
					//上边将文件中的数据全部发送出去并清空。
					//接下来继续打开该文件来等待网络断开后写入
					//现在可以写
					openSensorDataSave();
					fsIsUseToWrite= true;
				}
				#endif
				continue;
			}
			//网络断开
			else if(semaphoreFlag == -1)
			{
#ifdef  ROBOT_SENSOR_DATA_DELAY_SEND
				PRINT("控制台断开,正在创建传感器文件并收集传感器信息");
				//文件被打开用于存放数据
				openSensorDataSave();
				//网络断开,现在可以写
				fsIsUseToWrite = true;
#endif
				continue;
			}
			//PRINT("信号灯释放");
			if(getHaveFrontRobot() && !getFrontRobotIsConnected())
			{
				if(connectFrontRobot())
				{
					setFrontRobotIsConnected(true);
					PRINT("连接到前方机器人成功");
				}
				else
					PRINT("连接到前方机器人失败");
			}
			if(getHaveBackRobot() && !getBackRobotIsConnected())
			{
				if(connectBackRobot())
				{
					setBackRobotIsConnected(true);
					PRINT("连接到后方机器人成功");
				}
				else
					PRINT("连接到后方机器人失败");
			}
		}
	}
}
示例#8
0
static void rcvSensorData(u8_t volatile * data, unsigned char len)
{
  if(data[0] == '<')
  {
    switch(data[1])
    {
      case 'S':
        //<S:N,Sn>
        if((data[2] == ':') && ((data[3] - '0') < (NUM_SENS + 1)) && (data[4] == ','))
        {
        }
        else
        {
          sendError();
        }
      break;

      case 'A':
        //<A:N,An,T>
        if((data[2] == ':') && ((data[3] - '0') <= (NUM_ACIONADORES)) && (data[4] == ',') && (data[6] == ','))
        {
           //Seta o valor do acionador
           unsigned char num = data[3] - '0';
           unsigned char val = data[5] - '0';
           unsigned char tempo = 0;
           unsigned char i;

           i = 7;
           do
           {
              if((data[i] < '0') || (data[i] > '9'))
              {
              }
              else
              {
                 tempo *= 10;
                 tempo += (data[i] - '0');
                 i++;
              }
           }
           while(((data[i] >= '0') && (data[i] <= '9')) && (i < 11));

           if(i < 11)
           {
               if(!val)
               {
                 ioReleClear(num);
               }
               else if(val == 1)
               {
                 ioReleSet(num);

                 //Guardar valor do tempo de acionamento
                 //memoryData.tempoAcionador[num-1] = tempo << 1;
                 acionadorCount[num-1] = tempo << 1;
               }
           }
           else
           {
               //Erro no pacote de dados
               sendError();
           }
        }
        else
        {
            sendError();
        }
      break;

      case 'I':
        //<I:T:PPP.PPP.P.PPP>
        if((data[2] == ':') && ((data[3] == '0') || (data[3] == '1')) && (data[4] == ','))
        {
          unsigned char check;

          //Salva indicador do tipo de configuração DHCP ou estático
          memoryData.ipTipo = data[3];

          //Salva ip no caso de ip estático
          if(data[3] == '1')
          {
            unsigned char i;
            unsigned char ip;
            unsigned char count;

            ip = 0;
            count = 5;
            check = 0;
            for(i=0;i<4;i++)
            {
              do
              {
                if((data[count] < '0') || (data[count] > '9'))
                {
                  check=1;
                }
                ip *= 10;
                ip += (data[count] - '0');
                count++;
              }
              while((data[count] >= '0') && (data[count] <= '9'));

              count++;
              memoryData.ipEstatico[i] = ip;
              ip = 0;
            }
          }
          else
          {
            appWriteFlashData();
          }

          if(!check)
          {
             appWriteFlashData();
          }
        }
      break;

      case 'V':
        //<V>
        if(data[2] == '>')
        {
            //Monta o pacote de versão
            pbuffer[0] = '<';
            pbuffer[1] = 'V';
            pbuffer[2] = VERSION_MAJOR;
            pbuffer[3] = '.';
            pbuffer[4] = VERSION_MINOR;
            pbuffer[5] = '>';
            uip_send(pbuffer,6);
        }
        else
        {
            sendError();
        }
      break;

      case 'C':
        //<C:XXX.XXX.X.XXX,PPPP>
        //<C:www.servidor.com.br,PPPP>
         if(data[2] == ':')
         {
            unsigned char ip;
            unsigned char count;
            unsigned char i;

            if((data[3] >= '0') && (data[3] <= '9'))
            {
                memoryData.dns = 0;
                ip = 0;
                count = 3;
                for(i=0;i<4;i++)
                {
                    do
                    {
                        ip *= 10;
                        ip += (data[count] - '0');
                        count++;
                    }
                    while((data[count] >= '0') && (data[count] <= '9'));

                    memoryData.ipServidor[i] = ip;
                    ip = 0;
                    count++;
                }
                count--;
            }
            else
            {
                unsigned char countAdd;

                //Endereço será resolvido por dns
                memoryData.dns = 1;

                //Limpa memoria
                for(countAdd=0;countAdd<WEB_ADDR_SIZE;countAdd++)
                {
                    memoryData.webAddr[countAdd] = 0;
                }

                countAdd = 0;
                count = 3;
                //21 e 7F são valores imprimíveis na tablea ASCII incluindo letras maiúsculas, minúsculas e pontos
                while((data[count] != ',') && (data[count] > 0x21) && (data[count] < 0x7F) && (countAdd < WEB_ADDR_SIZE))
                {
                    memoryData.webAddr[countAdd] = data[count];
                    countAdd++;
                    count++;
                }
            }

            if(data[count] == ',')
            {
              unsigned int porta;
              count++;

              porta = 0;
              do
              {
                porta *=10;
                porta+=(data[count] - '0');
                count++;
              }
              while((data[count] >= '0') && (data[count] <= '9'));

              memoryData.porta = porta;
            }

            appWriteFlashData();
        }
        else
        {
            sendError();
        }
      break;

      case 'T':
        //<T:XXX>
        //XXX - Tempo entre pacotes de 0 a 256 décimos de segundo
        if(data[2] == ':')
        {
            unsigned char time;
            unsigned char count;

            time = 0;
            count = 3;
            do
            {
               time *= 10;
               time += (data[count] - '0');
               count++;
            }
            while((data[count] >= '0') && (data[count] <= '9'));

            memoryData.tempoPacote = time;
            ciclos = time/5;

            appWriteFlashData();
         }
         else
         {
            sendError();
         }
      break;

      case 'R':
        //<R>
        //Reinicia a aplicação
        uip_close();
        connected = 0;
        reboot = 1;
      break;

      case 'D':
        //<D>
        sendSensorData();
      break;

      case 'P':
        //<P>
        //Pacote de ping
        if(data[2] == '>')
        {
            //Monta o pacote de versão
            pbuffer[0] = '<';
            pbuffer[1] = 'A';
            pbuffer[2] = 'C';
            pbuffer[3] = 'K';
            pbuffer[4] = '>';

            uip_send(pbuffer,5);
        }
        else
        {
            sendError();
        }
      break;

      case 'N':
        //<N:TTT.TTT.TTT.TTT>
        if((data[2] == ':'))
        {
           unsigned char check;
           unsigned char i;
           unsigned char ip[4];
           unsigned char count;

           count = 3;
           check = 0;
           memoryData.dnsAddr[0] = 0;
           memoryData.dnsAddr[1] = 0;

           for(i=0;i<4;i++)
           {
              ip[i] = 0;

              do
              {
                if((data[count] < '0') || (data[count] > '9'))
                {
                  check=1;
                }
                ip[i] *= 10;
                ip[i] += (data[count] - '0');
                count++;
              }
              while((data[count] >= '0') && (data[count] <= '9'));

              count++;
            }

            memoryData.dnsAddr[0] = (unsigned int)ip[1];
            memoryData.dnsAddr[0] = memoryData.dnsAddr[0] << 8;
            memoryData.dnsAddr[0] += ip[0];
            memoryData.dnsAddr[1] = (unsigned int)ip[3];
            memoryData.dnsAddr[1] = memoryData.dnsAddr[1] << 8;
            memoryData.dnsAddr[1] += ip[2];

            if(!check)
            {
               appWriteFlashData();
            }
        }
      break;

      case 'B':
        //<B:TTT.TTT.TTT.TTT>
        if((data[2] == ':'))
        {
           unsigned char check;
           unsigned char i;
           unsigned char ip[4];
           unsigned char count;

           count = 3;
           check = 0;
           memoryData.drAddr[0] = 0;
           memoryData.drAddr[1] = 0;

           for(i=0;i<4;i++)
           {
              ip[i] = 0;

              do
              {
                if((data[count] < '0') || (data[count] > '9'))
                {
                  check=1;
                }
                ip[i] *= 10;
                ip[i] += (data[count] - '0');
                count++;
              }
              while((data[count] >= '0') && (data[count] <= '9'));

              count++;
            }

            //Grava valor do default router na memória
            memoryData.drAddr[0] = (unsigned int)ip[1];
            memoryData.drAddr[0] = memoryData.drAddr[0] << 8;
            memoryData.drAddr[0] += ip[0];
            memoryData.drAddr[1] = (unsigned int)ip[3];
            memoryData.drAddr[1] = memoryData.drAddr[1] << 8;
            memoryData.drAddr[1] += ip[2];

            if(!check)
            {
               appWriteFlashData();
            }
        }
      break;

      case 'M':
        //<M:XXX.XXX.X.XXX>
         if(data[2] == ':')
         {
            unsigned char ip;
            unsigned char count;
            unsigned char i;

            ip = 0;
            count = 3;
            for(i=0;i<4;i++)
            {
              do
              {
                ip *= 10;
                ip += (data[count] - '0');
                count++;
              }
              while((data[count] >= '0') && (data[count] <= '9'));

              memoryData.netMask[i] = ip;
              ip = 0;
              count++;
            }
            appWriteFlashData();
        }
        else
        {
            sendError();
        }
      break;
    }
  }
  else
  {
    sendError();
  }
}
示例#9
0
/*!  \brief Executa a aplicação que controla a conexão de rede */
void appCall(void)
{
  //Se conexão foi abortada envia reset e reboot do pc
  if(uip_aborted())
  {
      reboot = 1;
      connected = 0;
      dataSent = 0;
  }

  //Verifica se houve algum problema na conexão
  if(uip_timedout())
  {
    //Flag que indica erro na conexão
    connected = 0;
    //lcdPutString("D",1,15);
    dataSent = 0;
    enc28j60_init();

    //appSendConnect();
    if(memoryData.ipTipo == '0')
    {
       //Inicia o DHCP
       ethaddr.addr[0] = ENC28J60_MAC0;
       ethaddr.addr[1] = ENC28J60_MAC1;
       ethaddr.addr[2] = MAC_CONC[0];
       ethaddr.addr[3] = MAC_CONC[1];
       ethaddr.addr[4] = MAC_CONC[2];
       ethaddr.addr[5] = MAC_CONC[3];
       uip_setethaddr(ethaddr);
       dhcpc_init(&ethaddr, sizeof(ethaddr));
    }
    else
    {
       u16_t dns[2];

       //Inicia com ip fixo
       appInitHostIp();
       dns[0] = memoryData.dnsAddr[0];
       dns[1] = memoryData.dnsAddr[1];
       appSetDnsAddr(dns);
       appSendConnect();
    }
  }

  if(uip_closed())
  {
     WDTCTL = 0;
  }

  //Caso a conexão com o servidor acabou de ocorrer
  if(uip_connected())
  {
    connected = 1;
    //lcdPutString("C",1,15);
    dataSent = 0;
  }

  //Recebe os dados enviados pelo servidor
  if(uip_newdata() && connected)
  {
    rcvSensorData(uip_appdata,uip_len);
  }

  if(connected && (uip_acked()) && dataSent && (!repetAck))
  {
    dataSent = 0;

    //Diz que valor dos sensores já foi enviado
    sensorClear();
  }

  if(uip_rexmit() && connected && (uip_len == 0))
  {
    //Evita travamento da interface de rede
    enc28j60_init();

    //Envia os dados do sensor no caso de retransmissão
    sendSensorData();

    return;
  }

  //Transmite dados para o servidor
  if(uip_poll() && connected && (uip_len==0))
  {
    //Envia os dados dos sensores caso seja modo síncrono
    if(memoryData.tempoPacote != 0)
    {
      if(ciclos >= 1)
      {
        if(countBaud >= (ciclos -1))
        {
           countBaud = 0;
           sendSensorData();
           dataSent = 1;
        }
        else
        {
           countBaud++;
        }
      }
    }
  }
}
示例#10
-10
文件: Ospom.cpp 项目: ReefPOM/OSPOM
//This is the main function that gets called from the Arduino program
void Ospom::Run(int SensorReadDelayMS)
{
  //Having these written out twice as const int's saves a lot of RAM
  const int  EEPIDLoc[23] = {9,28,47,66,85,104,123,142,161,180,199,218,237,256,275,294,313,332,351,370};
	//Location of Element Type (Sensor, actuator, nothing)
  const int EEPTypLoc[23] = {17,36,55,74,93,112,131,150,169,188,207,226,245,264,283,302,321,340,359,378};
	//Location of Element Function (Analog Read, Digital Read, Analog Write, ect)
  const int EEPFuncLoc[23] = {18,37,56,75,94,113,132,151,170,189,208,227,246,265,284,303,322,341,360,379};
	//Location of Element Slope(if sensor) or Fail Safe(if actuator) value
  const int EEPSlopeFSLoc[23] = {20,39,58,77,96,115,134,153,172,191,210,229,248,267,286,305,324,343,362,381};
	//Location of Element Y-intercept(if sensor) or Extra(if actuator)
  const int EEPYintExLoc[23] = {24,43,62,81,100,119,138,157,176,195,214,233,252,271,290,309,328,347,366,385};

  unsigned long TimeNow = 0;
  static unsigned long SensorStreamStartTime;
  static unsigned long LastMeasurement;
  static unsigned long LastSend;
  static unsigned int SendDelay;

  if (TriacDimming) {
    triacDimming();
  }

  if (incomingUSBmsg()) {
    if (groupCommand) {
      //Do Group Command Stuff
      switch (groupCommandVal()) {
        case 0:
          sendGroupID();
          break;
        case 10:
          sendSensorData();
          break;
        case 11:
	  SendDelay = GroupCommandInt;  //Grab the time in milliseconds
          SensorStreamStartTime = millis();                   //to delay before sending again
          SendData = true;
          break;
        case 13:
          sendActuatorData();
          break;
        case 17:
          watchDog();
          break;
        case 18:
          setGroupID();
          break;
        default:
          fail();
          break;
      }
    }
	//Element Command Section accepts commands and takes action
    else if (ElementCommand) {
	//Store the Element ID we are working with in a temporary variable
      char ElementID[9] = "        ";  //A temporary Variable for the ELement ID
      EEPROM.readBlock<char>(EEPIDLoc[ElementNumber], ElementID, 8);  //Reads the Element ID from EEPROM
      //Do what the command Character says
      if (ElementCommandChar == 'R') {
         //Read the element value, and send it back to the odroid 
        Serial.print(GroupID);
        Serial.print("/");
        Serial.print(ElementID);
        Serial.print(":");
        Serial.println(ElementCalVal[ElementNumber]);
      }
      else if (ElementCommandChar == 'I') {
         //Change the Elements ID
        EEPROM.updateBlock<char>(EEPIDLoc[ElementNumber], CommandCharArray, 8);
        success();
      }
      else if (ElementCommandChar == 'T') {
         //Change the Elements Type (s = sensor, a = actuator, n = nothing, z=SetBy EEPROM Loader Program)
	EEPROM.write(EEPTypLoc[ElementNumber],CommandCharArray[0]);
	ElementType[ElementNumber] = EEPROM.read(EEPTypLoc[ElementNumber]);
        success();
      }
      else if (ElementCommandChar == 'C') {
         //Change the Elements Function (0=unused, 1=analogRead, 2=digitalRead, 3=analogWrite, 
			// 4=digitalWrite, 5=Triac, 10=SetBy EEPROM Loader Program)
	EEPROM.updateInt(EEPFuncLoc[ElementNumber], ElementCommandInt);
	ElementFunction[ElementNumber] = EEPROM.readInt(EEPFuncLoc[ElementNumber]);
        success();
      }
      else if (ElementCommandChar == 'A') {
	//Read the Element Type and Send it back to the odroid
	Serial.print(GroupID);
        Serial.print("/");
        Serial.print(ElementID);
        Serial.print(":");
        Serial.println(ElementType[ElementNumber]);
      }
      else if (ElementCommandChar == 'D') {
	//Read the Element Function and Send it back to the odroid
	Serial.print(GroupID);
        Serial.print("/");
        Serial.print(ElementID);
        Serial.print(":");
        Serial.println(ElementFunction[ElementNumber]);
      }
      else if (ElementCommandChar == 'M') {
        //Change the Elements Calibration Slope
        EEPROM.updateFloat(EEPSlopeFSLoc[ElementNumber], ElementCommandFloat);  //Save value to EEPROM);
        ElementSlopeFS[ElementNumber] = ElementCommandFloat;
        success();
      }
      else if (ElementCommandChar == 'B') {
        //Change the Elements Calibration Slope
        EEPROM.updateFloat(EEPYintExLoc[ElementNumber], ElementCommandFloat);  //Save value to EEPROM);
        ElementYintEx[ElementNumber] = ElementCommandFloat;
        success();
      }
      else if (ElementCommandChar == 'W') {
	//Write (Set) the Actuator
	if (ElementType[ElementNumber] == 'a') {  //Make sure it's an actuator (so we don't break sensors)
	  if ((ElementFunction[ElementNumber] == 3) && (ElementCommandInt != 100) && (ElementCommandInt != 0)) {  //AnalogWrite
	    if ((ElementCommandInt > 0) && (ElementCommandInt < 100)) {
	      ElementCalVal[ElementNumber] = ElementCommandInt;  //Save the Actuator Value so it can tell what it is if asked
	      ElementCommandInt = ElementCommandInt * 255 / 100; //convert to 0-255 for PWM
	      analogWrite(ElementPin[ElementNumber], ElementCommandInt);  //AnalogWrite (PWM) if it's a 1-99 value
	      success();
	    }
	    else {
	      fail();
	    }
	  }     //This does the digital writes, and also takes care of 100% on and 100% off PWM dimming
	  else if ((ElementFunction[ElementNumber] == 4) || (ElementFunction[ElementNumber] == 3)) {  //DigitalWrite
	    ElementCalVal[ElementNumber] = ElementCommandInt;  //Save the Actuator Value so it can tell what it is if asked
	    if (ElementCommandInt == 0) { //0 means turn off the actuator
	      digitalWrite(ElementPin[ElementNumber], LOW);
	      success();
	    }
	    else if (ElementCommandInt == 100) {  //100 means turn on the actuator
	      digitalWrite(ElementPin[ElementNumber], HIGH);
	      success();
	    }
	    else {
	      fail();
	    }
	  }
	  else if (ElementFunction[ElementNumber] == 5) { //Triac Dimming 115v/240v AC Outlets
	      //Decides if the input was appropriate, and sets the Stored Value betwenn 0 and 100 %
	    if (ElementCommandInt == 0) {
	      digitalWrite(ElementPin[ElementNumber], LOW);
	      ElementCalVal[ElementNumber] = ElementCommandInt;  //Save the Actuator Value so it can tell what it is if asked
	      success();
	    }
	    else if (ElementCommandInt == 100) {  //100 means turn on the outlet all the way
	      digitalWrite(ElementPin[ElementNumber], HIGH);
	      ElementCalVal[ElementNumber] = ElementCommandInt;
	      success();
	    }
	    else if ((ElementCommandInt > 0.00) && (ElementCommandInt < 100.00)) {
	      ElementCalVal[ElementNumber] = ElementCommandInt;
	      ElementTotalValue[ElementNumber] = ElementCalVal[ElementNumber];
	      ElementTotalValue[ElementNumber] = 80 * ElementTotalValue[ElementNumber];
	      ElementTotalValue[ElementNumber] = 8000 - ElementTotalValue[ElementNumber];
	      ElementYintEx[ElementNumber] = 1;
	    //  ElementCalVal[ElementNumber] = 80 * ElementCalVal[ElementNumber];  //convert to Delay:
            //  ElementCalVal[ElementNumber] = 8000 - ElementCalVal[ElementNumber];  // MilliDelay=8300-(83*%Dim)
	      Serial.println(ElementCalVal[ElementNumber]);
	      Serial.println(ElementTotalValue[ElementNumber]);
	      success();
	    }
	    else {
	      fail();
	    }
	      //Sets the TriacDimming Boolean to true if any of the outlets are dimmed between 1 and 99%
	    TriacDimming = false;
	    for (int i = 0; i < 20; i++) {
   	     if (ElementType[i] == 'a') {   //s = sensor, a = actuator, n = nothing
    	       if (ElementFunction[i] == 5) {  // 5=Triac Dimming
		 if ((ElementCalVal[i] < 100.00) && (ElementCalVal[i] > 0.00)) {
		   TriacDimming = true;
		 }
	       }
	     }
	   }
	  }
	  else {
	    fail();
	  }
   	}
	else {
	  fail();
	}
      }
      else if (ElementCommandChar == 'S') {  //Not sure if storing an in where a float goes sometimes will matter
	//Set Fail Safe Value
	EEPROM.updateInt(EEPSlopeFSLoc[ElementNumber], ElementCommandInt);
	ElementSlopeFS[ElementNumber] = ElementCommandInt;
        success();
      }
      else if (ElementCommandChar == 'F') {
	//Read Fail Safe Value
	Serial.print(GroupID);
        Serial.print("/");
        Serial.print(ElementID);
        Serial.print(":");
        Serial.println(EEPROM.readInt(EEPSlopeFSLoc[ElementNumber]));
      }
      else {
        fail();  //Return a -1
      }
      clearTheMsg(); 

    }
    else {
      fail();
    }

    clearTheMsg();
  }

  //Measure sensor elements (with the delay decided in the main sketch), put them in an array
  TimeNow = millis();  //Check the time
  if (TimeNow > LastMeasurement + SensorReadDelayMS) {
    LastMeasurement = millis();
    readSensors();  
  }

  //Send a Stream of Sensor Data for 1 minute if it has been requested
  if (SendData) {
    if (SensorStreamStartTime + 60000 > TimeNow)  {  //Send Data Stream
      if (Pause) {
        Pause = false;
      }
      else {
        if (TimeNow > LastSend + SendDelay) {
          sendSensorData();
          LastSend = millis();
        }
      }
    }
    else {  //  Stop Sending Data
      SendData = false;
      SensorStreamStartTime = 0;
      SendDelay = 0;
      LastSend = 0;
    }
  }
}