コード例 #1
0
ファイル: device.c プロジェクト: billev/literacybridge
void rtcAlarmFired(unsigned long alarm) {
	char buffer[48], wrk[12];
	void setNextAlarm();
	void removeAlarm(unsigned long);
	APP_IRAM static unsigned long lastActivity;
	
	strcpy(buffer,"rtcAlarmFired alarm=");
	unsignedlongToHexString((long)alarm, (char *)wrk);
	strcat(buffer, wrk);
	logString(buffer,ASAP,LOG_ALWAYS);
	
//  any rtc alarm not on hour 0 minute 0 will not reset an alarm 
	if(curAlarmSet) {
		removeAlarm(curAlarmSet);
		curAlarmSet = 0;
	}
	if((alarm & 0xffff) == 0) {
//	if(*P_Hour == 0 && *P_Minute == 0) { // bump systemcounters 
		loadSystemCounts();
		systemCounts.poweredDays += 1;
		systemCounts.monthday++;
		fixBadDate(&systemCounts);
		saveSystemCounts();
//		logRTC(); // remove
		while(*P_Second == 0) wait(100);
		strcpy(buffer,"poweredDays=");
		longToDecimalString(systemCounts.poweredDays, buffer+12, 4);
		logString(buffer,ASAP,LOG_ALWAYS);
		lastActivity = 0;  // if up when rollover prevent shutdown
//		resetRTC();
//		resetRTC23();  // test, really set rtc to 0,0,1sec
//		setRTCalarm(0, 0, 0);
	}
	setNextAlarm();
}
コード例 #2
0
ファイル: device.c プロジェクト: billev/literacybridge
void rtcAlarmFired(unsigned long alarm) {
	char buffer[48], wrk[12];
	void setNextAlarm();
	void removeAlarm(unsigned long);
	APP_IRAM static unsigned long lastActivity;
	
	strcpy(buffer,"rtcAlarmFired() alarm=");
	unsignedlongToHexString((long)alarm, (char *)wrk);
	strcat(buffer, wrk);
	logString(buffer,ASAP,LOG_ALWAYS);
	
	removeAlarm(alarm);	// remove from table if present

	if((alarm & 0x00ffffffL) == 0) {
//	if(*P_Hour == 0 && *P_Minute == 0) { // bump systemcounters 
		incrementCumulativeDays();
//		loadSystemCounts();
		//TODO:Redundant with Flash system counter
//		systemCounts.poweredDays += 1;
//		systemCounts.monthday++;
//		fixBadDate(&systemCounts);
//		saveSystemCounts();
//		logRTC(); // remove
		while(*P_Second == 0) wait(100);
		strcpy(buffer,"poweredDays=");
		longToDecimalString(getCumulativeDays(), buffer+12, 4);
		logString(buffer,ASAP,LOG_ALWAYS);
		lastActivity = 0;  // if up when rollover prevent shutdown
//		resetRTC();
//		resetRTC23();  // test, really set rtc to 0,0,1sec
//		setRTCalarm(0, 0, 0);
	}
	setNextAlarm();
}
コード例 #3
0
ファイル: device.c プロジェクト: billev/literacybridge
unsigned long
addAlarm(unsigned int hour, unsigned int minute, unsigned int second) {
	void setNextAlarm();
	char buf[48], strbuf[12];
	int i, insertpos;
	unsigned long newAlarm;
	
	while(hour >= 24)
		hour -= 24;
	while(minute >= 60)
		minute -= 60;
	while(second >= 60)
		second -= 60;
	
	newAlarm = getTimeinSeconds(hour, minute, second);
	
	for(i=0; i<N_RTC_ALARMS; i++) {
		if((rtcAlarm[i] == 0) || (newAlarm < rtcAlarm[i])) 
			break;
		if(newAlarm && (newAlarm == rtcAlarm[i])) {
			return(newAlarm);
		}
	}
	insertpos = i;
	if(rtcAlarm[insertpos] != 0) {
		for(i=N_RTC_ALARMS-1; i>=insertpos; i--) {
			rtcAlarm[i+1] = rtcAlarm[i];
		}
	}
	rtcAlarm[insertpos] = newAlarm;
	
	strcpy(buf,"add new alarm at position ");
	longToDecimalString(insertpos, (char *)strbuf, 2); 
	strcat(buf, strbuf);
	strcat(buf," alarm time ");
	unsignedlongToHexString((unsigned long)newAlarm, (char *)strbuf);
	strcat(buf, strbuf);
	logString(buf,BUFFER,LOG_NORMAL); 
	
	
	setNextAlarm();
	
	return(newAlarm);
}
コード例 #4
0
void SmartMote::work(){
    while(1){
        /*  se l'ora corrente è di scansione                                    */
        if(!(RTCC.hours() % 6) && (RTCC.minutes() >= 0x00 && RTCC.minutes() <= 0x05)){
            AString data;
            AString message;
            AString answer;
            /*  abilito il core timer (la prima volta è già abilitato)          */
            System::wakeCoreTimer();
            /*  accendo il led verde                                            */
            turnOnGreen();
            /*  accendo la seriale                                              */
            openUART();
            /*  accendo l'i2c                                                   */
            openI2C();
            /*  prendo le misure                                                */
            data += mac();
            data += luminosity();
            data += ambientTempAndHum();
            data += groundTemp();
            data += groundHum();
            data += battey();
            /*  compongo la stringa                                             */
            message += _PHP_CHUNK1;
            /*  inserisco l'hostname                                            */
            message += getHost();
            /*  inserisco la seconda parte di richiesta http                    */
            message += _PHP_CHUNK2;
            /*  inserisco la lunghezza dei dati                                 */
            message += AString(static_cast<sint32>(data.size()));
            /*  inserisco la terza parte di richiesta http                      */
            message += _PHP_CHUNK3;
            /*  inserisco i dati                                                */
            message += data;

            /*  se fallisce l'inizializzazione dell'esp                         */
            if(!m_net.initialize()){
                /*  notifico l'errore                                           */
                error();
            }
            /*  se fallisce l'avvio del dhcp                                    */
            if(!m_net.setDhcp(true)){
                /*  notifico l'errore                                           */
                error();
            }
            /*  se fallisce la connessione alla rete                            */
            if(!m_net.joinAP(getSSID(), getKey())){
                /*  notifico l'errore                                           */
                error();
            }
            /*  se fallisce la connessione al server                            */
            if(!m_net.connectToHost(getHost(), 80)){
                /*  notifico l'errore                                           */
                error();
            }
            /*  invio i dati                                                    */
            m_net.send(message);
            /*  aspetto l'ok                                                    */
            m_net.waitForData(answer);
            /*  notifico l'ok o lerrore dell'invio                              */
            wasSuccess(answer);
            /*  lascio l'ap                                                     */
            m_net.leaveAP();
            /*  libero la memoria occupata dalle stringhe                       */
            message.clear();
            data.clear();
            answer.clear();
        }
        /*  calcolo del tempo di sleep per il wifi                              */
        m_net.sleep(getSleepTime());
        /*  punto la prossima sveglia                                           */
        setNextAlarm();
        /*  spengo il led verde                                                 */
        turnOffGreen();
        /*  spengo l'uart                                                       */
        closeUART();
        /*  chiudo l'i2c                                                        */
        closeI2C();
        /*  spengo il core timer                                                */
        System::stopCoreTimer();
        /*  vado a dormire                                                      */
        System::sleep();
            
    }
}