Exemple #1
0
void UART_write(char* commandPtr, char* readingPtr)
{
    char temp[10] = "test";
    
    if (commandPtr[0] == 'p') {
        // read the pulse
        // temp[0] = pulseRate();
        sprintf(readingPtr,"Pulse: %02u \n", temp[0]);
        delay(1000);
    }
    else if (commandPtr[0] == 's') {
        // read the systolic
        // temp[0] = bloodPres1();
        sprintf(readingPtr,"Syst: %02u \n", temp[0]);
        delay(1000);
    }
    else if (commandPtr[0] == 'd') {
        // read the diastolic
        // temp[0] = bloodPres2();
        sprintf(readingPtr,"Diast: %02u \n", temp[0]);
        delay(1000);
    }
    else if (commandPtr[0] == 't') {
        // read the temp[0]
        // temp[0] = getTemp[0]();
        sprintf(readingPtr,"Temp[0]: %02u \n", temp[0]);
        delay(1000);
    }
    puts1USART(readingPtr);
}
void demo_test(){
    tempcounter=2;
    char c=0;
    //if(SolarStatus()==1){
        if (BatteryCharged()){
//            if (ReadInitFlag()==0){                             //check if its first initialisation of device
//                GSM_ON();                                       //turn on GSM module
//                SIM900_SEND(2);                                 //send a configuration request message to server
//                SetInitFlag();                                  //set initcheck flag
//            }
            for (char d=0; d<TRANSMIT_FREQ; d++){
                days++;                                         //increment days
                for (int i=0; i<tempcounter; i++){
                    getTempHum();                               //get temperature and humidity sensor
                    while ((TEMP_INT==0)&&(c<=3)){              //check DHT11 sensor 3 times for reading if no data received
                        getTempHum();
                        c++;
                    }
                    DayTEMP[i]=TEMP_INT;
                    DayHUM[i]=RH_INT;
                    delay_1s(3);                               //wait 30 seconds between each temperature readings
                }
                avgTempHum();                                   //calculate average temperature and humidity
                minmaxTempHum();                                //calculate minimum and maximum temperature and humidity
                getWaterLevel();                                //get water level from ultrasonic sensor
                getConductivity();
                getSolarReading();
                getBatteryReading();
                ShiftData();                                    //shift gathered data by offset
                if ((WaterLevel-OFFSET) >= WATER_THRESHOLD){    //check if water level is too low
                    SMS_data[0]=WARNING_PREFIX;                 //initiate message with warning char
                    SMS_data[1]=WaterLevel;                     //put water level in text message
                    SMS_data[2]=DATA_SUFFIX;                    //end message with suffix

                    GSM_ON();                                   //turn on sim900
                    delay_1s(5);                               //wait for GSM to connect to network
                    SIM900_SEND(1);                             //Send data message to server
                    GSM_OFF();                                  //turn off sim900
                }
                SaveData();                                     //Sava sensor readings to memory
            }
        }
        if (!BatteryCharged()){
            MonitorBattery();
        }
    SMS_data[0]=DATA_PREFIX;                            //start message with prefix
    gatherData();                                       //read data from memory
    getCheckByte();                                     //calculate check byte
    GSM_ON();                                           //turn on sim900
    delay_1s(10);                                       //wait for GSM to connect to network
    puts1USART("AT\r\n");
    delay_1s(5);
    SIM900_SEND(1);                                     //Send data message to server
   //} //solarpanel check
}
// This function is called repeatedly
void loop(void) {
    // Temporary storage variables
    unsigned int i;
    unsigned char temperature;
    unsigned char data;
    char buffer[50];

    // Check if the serial port has overflown, and clear the event if that happened.
    if (RCSTAbits.OERR) {
      RCSTA1bits.CREN = 0;
      RCSTA1bits.CREN = 1;
    }

    // Check if there is serial data waiting for us
    if (receiveCharacter != 0) {

        // See if we got a command
        switch (receiveCharacter) {
          case 'm':       // Measure the current temperature
            // Read the temperature
            temperature = readTemperature();

            // Write the results out to a string
            sprintf(buffer,"The current temperature is: %u\n\r", temperature);

            // Then send that string to the serial port
            puts1USART(buffer);
            break;
          case 'b':       // Begin logging
            sprintf(buffer,"Logging started\n\r");
            puts1USART(buffer);
            logging = 1;
            break;
          case 'e':       // End logging
            sprintf(buffer,"Logging stopped\n\r");
            puts1USART(buffer);
            logging = 0;
            break;
          case 'd':       // Get the logged data
            sprintf(buffer,"Getting %u measurements: ", logCount);
            puts1USART(buffer);
            for (i = 0; i < logCount; i++) {
                temperature = readEEPROM( i );
                // Write the results out to a string
                sprintf(buffer,"%u, ", temperature);

                // Then send that string to the serial port
                puts1USART(buffer);
            }
            sprintf(buffer,"\n\r", temperature);
            puts1USART(buffer);
            break;
          case 'r':       // Reset the logger, clearing all data
            sprintf(buffer,"Logger reset\n\r");
            puts1USART(buffer);
            logging = 0;
            logCount = 0;
            intervalCounter = 0;
            break;
        }

        receiveCharacter = 0;
    }

    // Wait for one second
    wait(1);

    // If data logging is enabled, see if we should log some now.   
    if ( logging ) {
        // Record that another second has passed
        intervalCounter++;

        // If we have waited for enough time, measure the current temperature
        if (intervalCounter >= logInterval) {
            // Turn on the LED to signal that a log event is happening
            PORTAbits.RA0 = 1;

            // Reset the seconds counter
            intervalCounter = 0;

            // Read the temperature
            temperature = readTemperature();

            // And record it in the EEPROM
            writeEEPROM( logCount, temperature );

            // Then record that we have taken another sample
            logCount++;

            // And turn off the LED
            PORTAbits.RA0 = 0;
        }
    }

}