void loop() { DHT22_ERROR_t errorCode; lcd.setCursor(0, 0); delay(2000); lcd.print('Requesting Data'); errorCode = rht.readData(); lcd.clear(); switch(errorCode) { case DHT_ERROR_NONE: lcd.print('T: ' << rht.getTemperatureC() << 'C'); lcd.setCursor(0, 1); lcd.print('RH: ' << rht.getHumidity() << '%'); break; case DHT_ERROR_CHECKSUM: lcd.print('T: ' << rht.getTemperatureC() << 'C *'); lcd.setCursor(0, 1); lcd.print('RH: ' << rht.getHumidity() << '% *'); break; case DHT_BUS_HUNG: printError('BUS Hung'); break; case DHT_ERROR_NOT_PRESENT: printError('Not Present'); break; case DHT_ERROR_ACK_TOO_LONG: printError('ACK timeout'); break; case DHT_ERROR_SYNC_TIMEOUT: printError('Sync timeout'); break; case DHT_ERROR_DATA_TIMEOUT: printError('Data timeout'); break; case DHT_ERROR_TOOQUICK: printError('Poll too quickly'); break; } }
inline void W5100_poll(void) { uint8_t sockstat; uint16_t rsize; uint8_t sockreg = 0; sockstat = SPI_Read(W5100_S0_SR); switch (sockstat) { case SOCK_CLOSED: if (socket(sockreg, MR_TCP, W5100_TCP_PORT) > 0) { // Listen to Socket 0 if (listen(sockreg) <= 0) _delay_ms(1); } break; case SOCK_ESTABLISHED: rsize = recv_size(); if (rsize > 0) { // Now read the client Request if (recv(sockreg, W5100_buffer, rsize) <= 0) break; // Create the HTTP Response Header http_header_xml(W5100_buffer); //Start with a http header D.get_xml_data(W5100_buffer); // sensor data if (send(sockreg, W5100_buffer, strlen((char *) W5100_buffer)) <= 0) break; // send out _delay_us(1); disconnect(sockreg); } else { _delay_us(10); // Wait for request } break; case SOCK_FIN_WAIT: case SOCK_CLOSING: case SOCK_TIME_WAIT: case SOCK_CLOSE_WAIT: case SOCK_LAST_ACK: // Force to close the socket close(sockreg); break; }; };
int SENSORS::getSensorValue(byte port, int deviceID) { int aInPin; int dInPin; int sensorValue; static int tempValue; if(port == 1){ aInPin = ADC_PIN_P1_1; dInPin = IO_PIN_P1_1; } else if (port == 2) { aInPin = ADC_PIN_P2_1; dInPin = IO_PIN_P2_1; } else if (port == 3) { aInPin = ADC_PIN_P3_1; dInPin = IO_PIN_P3_1; } else { //Serial.println("--> ERROR"); //Serial.print("--> Attempting to assign port: "); } switch (deviceID) { case 0: // UNKNOWN Sensor, pass in the ADC Value pinMode(aInPin, INPUT); sensorValue = analogRead(aInPin); return sensorValue; case 5: // Push Button Sensor pinMode(dInPin, INPUT); sensorValue = digitalRead(dInPin) * 1023; if (sensorValue==0) nOBJECTS.blinkLED(BLUE_LED_PIN); return sensorValue; case 6: // Light Sensor pinMode(aInPin, INPUT); sensorValue = analogRead(aInPin); return sensorValue; case 7: // PIR Sensor pinMode(dInPin, INPUT); sensorValue = digitalRead(dInPin) * 1023; if (sensorValue>0) nOBJECTS.blinkLED(GREEN_LED_PIN); return sensorValue; case 8: // DHT22 Humidity Sensor myDHT22.setPIN(dInPin); errorCode = myDHT22.readData(); if ((errorCode==DHT_ERROR_NONE) || (errorCode==DHT_ERROR_TOOQUICK)) { sensorValue = myDHT22.getHumidity() * 10 ; // make a single decimal float to int tempValue = myDHT22.getTemperatureC() * 10; // make a single decimal float to int return sensorValue; } else return 0; case 9: // DHT22 Temperature Sensor return tempValue; case 10: // Distance Sensor pinMode(aInPin, INPUT); sensorValue = analogRead(aInPin); return sensorValue; case 11: // 433Mhz Receiver - Not required to return anything // Special handling in doPort1() return -1; case 12: pinMode(aInPin, INPUT); sensorValue = analogRead(aInPin); if (sensorValue>0) nOBJECTS.blinkLED(RED_LED_PIN); return sensorValue; case 1002: // Relay Breakout pinMode(dInPin, OUTPUT); if (port == 1) sensorValue = bitRead(PORTC, 0); else if (port == 2) sensorValue = bitRead(PORTC, 1); else if (port == 3) sensorValue = bitRead(PORTC, 2); return sensorValue; default: // Invalid sensor ID return -1; } }