我的项目使用力感应电阻来检测占用情况。计时器将计算占用时间并更新服务器。我想让ESP8266 wifi芯片进入睡眠状态,而不是在整个使用过程中保持清醒状态。目的是节省不必要的电池消耗。
是否可以对占用时间和人离开椅子的时间进行快照以计算占用时间?
if(sensorReading >= 150) // Condition when someone is sitting; sensitivity level.
{
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
client.print("[Chair is occupied]\r\n");
digitalWrite(2,LOW); // When condition is true, Blue LED light up for as long User1 is sitting.
colorWipe(strip.Color(255, 0, 0), 50); // Red; (x,x,x) is the colour decimal, <number> refers to the speed at which the dots are occupied.
if(count ==0)
{
StarWars();
count++;
}
else
{
noTone(SPEAKER);
}
finished=millis(); // End stopwatch timer count
duration=finished-start;
h=int(duration/3600000); // conversion to hours from ms (60*60*1000)
over=duration%3600000;
m=int(over/60000); // conversion to mins from ms (60*1000)
over=over%60000;
s=int(over/1000); // conversion to sec from ms (1000)
ms=over%1000;
client.print(" Duration of occupancy: ");
client.print(h,0); // show only integer
client.print("h ");
client.print(m,0); // show only integer
client.print("m ");
client.print(s,0); // show only integer
client.print("s ");
client.print(ms,0); // show only integer
client.println("ms");
a = TotalTime; // let a = TotalTime
b = duration; // let b = duration
}