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 }
void ARRAY3600OBJ::setParameters(byte address, int maxI, int maxU, int maxP, int u) { byte command[] = { 0xAA, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; command[1] = address; command[3] = getLowByte(maxI); command[4] = getHighByte(maxI); command[5] = getLowByte(maxU); command[6] = getHighByte(maxU); command[9] = getLowByte(maxP); command[10] = getHighByte(maxP); command[11] = getLowByte(u); command[12] = getHighByte(u); command[25] = getCheckByte(command); WriteComPort(comdev, command, 26); }
void ARRAY3600OBJ::setToPcControlOff() { byte command[] = { 0xAA, 0x00, 0x82, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E }; command[25] = getCheckByte(command); WriteComPort(comdev, command, 26); }
void routine(){ START: if(SolarStatus()==1){ //if solar-panel is on solarcounter = 0; while (BatteryCharged()){ //if battery is charged 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 } char c=0; while ((TEMP_INT==0)&&(c<=3)){ //check DHT11 sensor 3 times for reading if no data received getTempHum(); c++; } DayTEMP[tempcounter]=TEMP_INT; DayHUM[tempcounter]=RH_INT; tempcounter++; delay_1ms(1); sleep(); if (tempcounter==2){ days++; //increment days avgTempHum(); //calculate average temperature and humidity minmaxTempHum(); //calculate minimum and maximum temperature and humidity getConductivity(); //get conductivity value from sensor getWaterLevel(); //get water level from ultrasonic sensor 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(10); //wait for GSM to connect to network SIM900_SEND(1); //Send data message to server } } } if (!BatteryCharged()){ MonitorBattery(); } if (SolarStatus()==0) //if solar-panel is off goto OFF; goto START; } else { //when solar-panel is off OFF: SaveData(); //Sava sensor readings to memory tempcounter=0; //check if data transmission frequency is met if (days >= TRANSMIT_FREQ){ 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 SIM900_SEND(1); //Send data message to server days=0; } //reset days counter only after successful tranmsission //sleep for 6h for (char z=0; z<3; z++){ sleep(); } while (SolarStatus()==2){ //if solar-panel is off for (char z=0; z<5; z++){ delay_1s(60); } solarcounter++; if (solarcounter > SOLAR_THRESHOLD){ //turn on Fault LED goto START; } } } }