Paul Langdon
Published © CC BY-NC-SA

Urban FarmBot LinkIt ONE IoT Edition

My kale is smarter than your honor roll student.

BeginnerWork in progress822
Urban FarmBot LinkIt ONE IoT Edition

Things used in this project

Hardware components

Grove Starter Kit for LinkIt ONE
Seeed Studio Grove Starter Kit for LinkIt ONE
×1
Ikea Samla container
×2
Ikea Odla Growing Media
×1

Software apps and online services

ThingSpeak

Story

Read more

Custom parts and enclosures

Ikea Odla Growing Media

Growing media to retain moisture and grow your plants

Ikea Samla Box - Black

Bottom section of your grow box

Ikea Samla Box - White

Top section of your grow box.

Code

Connect to WiFi

Arduino
This is an example of how you connect to your WiFI
#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
}

Get Temperature

Arduino
This is how you get the temperature reading
/****************************************************************************
 * 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;
}

Credits

Paul Langdon

Paul Langdon

49 projects • 319 followers
Working as a cloud architect for an IoT hardware company

Comments