Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Ashok R
Published

IoT Green Kit

Home and gardening automation with IoT network (Thread).

IntermediateShowcase (no instructions)Over 3 days983

Things used in this project

Hardware components

Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1
KW41z- Shield Board
×2
MikroElektronika - WiFi3 click
×1
Solenoid Valve
×1
LED Lamp Light
×1

Software apps and online services

IoT Box App
NXP MCUXpresso IDE

Story

Read more

Schematics

Schematic Blocks

Code

LPC804 Code

C/C++
/*
 * The Clear BSD License
 * Copyright (c) 2017, NXP Semiconductors, Inc.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted (subject to the limitations in the disclaimer below) provided
 *  that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "board.h"
#include "fsl_usart.h"

#include "pin_mux.h"
#include <stdbool.h>
#include "usart.h"
#include "timer.h"
#include "sense.h"
#include "oled.h"
#include "config.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/

#define ECHO_BUFFER_LENGTH 8
#define SUCCESS 0
#define TICK_DELAY_5S 5000
#define TICK_DELAY_2S 2000
#define TICK_DELAY_1S 2000
#define STARTUP_DELAY 1000
#define PWM_PERIOD 2000 //20ms

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
senseData_t value;
uint8_t app_mode = 1;
extern uint8_t field1[],field2[];
extern volatile bool wifi_connected;
extern volatile bool timeoutFlag;
extern volatile bool ap_connected;
extern volatile bool rxBlockReceived;
extern volatile int rxDataLength;
extern uint8_t app_pwmData[12];
volatile bool appReady;
volatile uint32_t g_systickCounter;

volatile bool led1_status = false;

/*******************************************************************************
 * Code
 ******************************************************************************/
void delay(uint32_t t)
{
    volatile uint32_t i = 0;
    for (i = 0; i < (540*t); ++i)
    {
        __asm("NOP"); /* delay */
    }
}

static uint8_t read_mode(){

	return (GPIO_PortRead(GPIO, APP_MODE_SW_PORT)>>APP_MODE_SW_PIN) & 0x1;
}

static void UpdateFields(){

	field1[8]= (value.temprature/100) + '0';
	field1[9]= ((value.temprature/10)%10) + '0';
	field1[10]= (value.temprature%10) + '0';

	field2[8]= (value.humidity/100) + '0';
	field2[9]= ((value.humidity/10)%10) + '0';
	field2[10]= (value.humidity%10) + '0';
}

void SysTick_Handler(void)
{

    g_systickCounter++;

}

/*!
 * @brief Main function
 */
int main(void)
{
	uint8_t ret =1;
    /* Initialize the pins. */
    BOARD_InitPins();
    /* Enable clock. */
    BOARD_InitBootClocks();
    /* Select the main clock as source clock of USART0. */
    CLOCK_Select(kUART0_Clk_From_MainClk);
    CLOCK_Select(kUART1_Clk_From_MainClk);
    /* Select the main clock as source clock of I2C0. */
    CLOCK_Select(kI2C0_Clk_From_MainClk);

    /* Set systick reload value to generate 1ms interrupt */
      if(SysTick_Config(SystemCoreClock / 100000U))
      {
          while(1)
          {
          }
      }

    Timer_Init();


    LED_BLUE_INIT(0);

    /* Initialize USART with configuration. */
    DEBUG_USARTInit();

    delay(STARTUP_DELAY);

    ESP_USARTInit();

    /* Initialize ESP with AT configuration */

	ap_connected = false;

	if(!read_mode()){

		ret = Esp_Init();
	}
	else{

		ret = Esp_AP_Init();

	}

    while (1)
    {


    	if(!ESP_GetLEDStatus()){

    		LED_BLUE_ON();
    	}
    	else{

    		LED_BLUE_OFF();
    	}



    }
}

Router Code

C/C++
Lib's Part not included
   while (1)
    {

    	if(g_ButtonPress){


    		switch(g_ButtonValue){

    		case 0:


    			break;

    		case 1:

    			g_AppIndex++;
    			if(g_AppIndex>=APP_MAX_COUNT) g_AppIndex =0;
    			draw_apppage(g_AppIndex, g_AppStatus[g_AppIndex], g_AppValue[g_AppIndex]);

    			break;

    		case 2:

    			if(g_AppIndex>2){

    				g_AppValue[g_AppIndex]++;

    				if(g_AppValue[g_AppIndex]>2)g_AppValue[g_AppIndex]=0;

    				draw_textbox(g_AppIndex, g_AppValue[g_AppIndex]);

    			}
    			else{

    				if(g_AppStatus[g_AppIndex]){

						draw_togglebutton_anime(64,140,0);
						draw_appicon(g_AppIndex,0);
						Write_Node(g_AppIndex, 0);
					}
					else{

						draw_togglebutton_anime(64,140,1);
						draw_appicon(g_AppIndex,1);
						Write_Node(g_AppIndex, 1);
					}
        			g_AppStatus[g_AppIndex] = 1-g_AppStatus[g_AppIndex];
    			}

    			break;

    		case 3:


    			//g_AppIndex--;
    			//if(g_AppIndex<0 || g_AppIndex>APP_MAX_COUNT) g_AppIndex =APP_MAX_COUNT;
    			//draw_apppage(g_AppIndex, g_AppStatus[g_AppIndex], g_AppValue[g_AppIndex]);


    			break;

    		}


			g_ButtonValue = 0;
			g_ButtonPress = false;

    	}
    	else{

    		if(g_AppStatus[2]==1 ){
				App_WaitMsec(10);
				g_cloud_counter++;

				if(g_cloud_counter>= APP_CLOUD_TIMER){

					ret |= ESP_ReadCloud();
					g_cloud_counter=0;
					g_AppStatus[0] =cfield1;
					g_AppStatus[1] =cfield2;
					Write_Node(0, cfield1);
					Write_Node(1, cfield2);


				}

    		}

    	}


    }
}

Credits

Ashok R

Ashok R

37 projects • 102 followers
Hobbyist/Engineer/Director/Animatior

Comments