Hardware components | ||||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
This is a monitoring prototype using the MediaTek LinkIt One that measures temperature and humidity for an easy to make window garden you can build with under $10 worth of Ikea parts.
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LFlash.h>
#define WIFI_EN 0
#define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your AP
/****************************************************************************
* get ssid & key
****************************************************************************/
#define WIFI_AP __BUF_SSID
#define WIFI_PASSWORD __BUF_KEY
char __BUF_SSID[50];
char __BUF_KEY[50];
#define Drv LFlash
bool get_ssid_key()
{
//delay(3000);
LTask.begin();
Drv.begin();
if(Drv.exists("wifi.txt"))
{
LFile f = Drv.open("wifi.txt", FILE_READ);
f.seek(0);
char __buf[100];
int len = f.size();
f.read(__buf, len);
__buf[len] = '\0';
#if DBG
Serial.print("file size: ");
Serial.println(f.size());
Serial.println("data:");
Serial.println(__buf);
#endif
int len_ssid = 0;
int __index = 5;
while(1) // set ssid
{
if(__buf[__index] != 0x0D)
{
__BUF_SSID[len_ssid++] = __buf[__index++];
}
else
{
__BUF_SSID[len_ssid] = '\0';
break;
}
}
int len_key = 0;
__index = 5+6+len_ssid;
while(1)
{
if(__buf[__index] != 0x0D)
{
__BUF_KEY[len_key++] = __buf[__index++];
}
else
{
__BUF_SSID[len_key] = '\0';
break;
}
}
f.close();
debug_oled(1, "READ SD OK");
return true;
}
debug_oled(1, "READ SD NOK");
while(1);
}
/****************************************************************************
* Wi-Fi Initialize
****************************************************************************/
bool wifi_init()
{
#if WIFI_EN
LWiFi.begin();
unsigned long timer_w = millis();
while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
{
if(millis() - timer_w > 30000)
{
return false;
}
checkSms();
}
delay(1000);
return true;
#else
return true;
#endif
}
/****************************************************************************
* Temperature
****************************************************************************/
const int numReadings = 10;
float readings[numReadings]; // the readings from the analog input
int __index = 0; // the __index of the current reading
float total = 0; // the running total
void tempInit()
{
for (int thisReading = 0; thisReading < numReadings; thisReading++)
{
readings[thisReading] = 0;
}
float h, t;
while(1)
{
if(dht.readHT(&t, &h))
{
for(int i=0; i<10; i++)
{
pushTemp(t);
}
break;
}
delay(2500);
}
}
void pushTemp(float __t)
{
total = total - readings[__index];
readings[__index] = __t;
total = total + readings[__index];
__index = __index + 1;
if (__index >= numReadings)
__index = 0;
__GTemp = total / numReadings;
}
bool getTempHumi()
{
static long timer_th = millis();
if(millis() - timer_th < 2000)return false;
timer_th = millis();
float h = 0.0;
float t = 0.0;
if(dht.readHT(&t, &h))
{
pushTemp(t);
__GHumi = h;
flg_temp_new = 1;
flg_humi_new = 1;
return true;
}
return false;
}
Comments