youtube link - renesas electronicstool-cloud.renesas.com/eddir/files/smart_home.pdf ·...

20
Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA Team Members: Abhijit Nathwani & Jaydev Dave Page1 “ENERGY EFFICIENT AI POWERED IOT SMART HOME” Renesas GR Lychee Design Contest 2K18 YouTube Link https://www.youtube.com/watch?v=jkyPx_DUooA Team ID: IoT Geek Team Member: Abhijit Nathwani and Jaydev Dave WhileOne Technologies Pvt. Ltd. Special Thanks to Renesas, India And Gadget Renesas Forum for Kind Support

Upload: others

Post on 06-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

“ENERGY EFFICIENT AI POWERED IOT SMART HOME”

Renesas GR Lychee Design Contest 2K18

YouTube Link

https://www.youtube.com/watch?v=jkyPx_DUooA

Team ID: IoT Geek

Team Member: Abhijit Nathwani and Jaydev Dave

WhileOne Technologies Pvt. Ltd.

Special Thanks to

Renesas, India And Gadget Renesas Forum

for Kind Support

Page 2: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age2

Abstract:

Our Goal is to design energy efficient IoT based home automation system for future smart home

using GR Lychee. GR Lychee will be heart of the project, it is connected to internet via Wi-Fi

connection using ESP32 onboard. Camera connected to GR Lychee detects any motion using motion

detection algorithm running on GR Lychee and captures image when motion detected and send it to

the android app running on user mobile via internet over Wi-Fi. Also user can set pan/tilt angle of

camera by servo motors and capture and receive image of the home by Android App via internet.

Many Wireless sensors and actuators are communicating to GR Lychee using NRF24L01 Transceiver

connected to GR Lychee using SPI protocol. The data of sensors are sent to Amazon AWS Server using

WiFi by GR Lychee, where AI algorithm used to efficiently trigger Light/Fan/AC based on training data

and reduce overall power consumption of the home. Further Android App can trigger the actuators

manually too and all sensor data are displayed in mobile app in realtime.

Each wireless sensor nodes are powered using normal room light/mechanical effort.

Sensors:

1. reed switch based magnetic door open/close sensor (STM 320 Solar Powered)

2. DHT 11 temperature and Soil Moisture sensor. (STM330 Solar Powered)

3. Rocker Switch (Mechanical Energy Harvesting)

Actuators:

1. RGB Mood Lighting Wireless Control module. (nRF24l01)

2. Relay module to turn on/off appliances. (nRF24l01)

Page 3: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age3

Block Diagram:

GR Lychee Board : Its Heart of the project connected to nRF24l01 TXRX (2.4GHz ISM) using SPI Bus

and EnOcean TCM210 RX (868MHz ISM) using UART Bus. Camera capture image on user demand as

well as when motion detected. ESP32 provides Internet Access of GR Smarthome Hub via MQTT.

Android App is designed using Processing IDE and GR Lychee firmware designed using Gr-ide.

Android App provides real time access to camera and various sensor module data as well as user can

control Relay switches and RGB LEDs. Captured images also stored on mobile phone storage with

time stamp.

Page 4: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age4

Hardware Setup:

Following are pics of Hardware Assembly followed by screenshots of Android App. We have

Designed Leser cut Enclosure for this project using Autodesk Fusion 360 for provide product like look

and feel.

Page 5: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age5

Page 6: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age6

Page 7: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age7

Page 8: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age8

Page 9: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age9

Page 10: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

0

Code for GR Lychee:

// =====================================================================

// GR Lychee Based Energy Efficient SMARTHOME IoT HUB

// GR-Lychee Design Contest-2018

// Team : IoT geek (WhileOne Technologies Pvt. Ltd.)

// Date : 01/09/2018

// Revision: Rev-01

// ======================================================================

// Include necessary Header files

#include <Arduino.h>

#include <string.h>

#include <mbed.h>

#include <Camera.h>

#include <opencv.hpp>

#include <ESP32.h>

#include <SPI.h>

#include "Enrf24.h"

#include "nRF24L01.h"

#include <Wire.h>

#include "SSD1306.h"

#include "images.h" // Include custom images

#define MOTION_TH 5.0 // Decrease to improve sensitivity of motion detection

#define IMAGE_HW 320

#define IMAGE_VW 240

#define WIFI_SSID "xxxxxxxxxx" // Your WiFi Network SSID Goes Hear

#define WIFI_PW "pppppppppp" // Your WiFi Network Password Goes Here

#define BROKER "35.230.211.125"// MQTT Broker url(tcp://...) or IP Address Goes Here

#define PING_INTERVAL 10000

#define MASK_INTERVAL 4000

#define UPDATE_INTERVAL 15000

#define DISP_INTERVAL 3000

SSD1306 display(0x3c, D3, D5);

Enrf24 radio(2,3,4); // P2.0=CE, P1.3=CSN, P1.4=IRQ

void dump_radio_status_to_serialport(uint8_t);

Page 11: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

1

using namespace cv;

static Camera camera(IMAGE_HW, IMAGE_VW);

ESP32 wifi(P5_3, P3_14, P7_1, P0_1,false,NC,NC,1000000);

byte connectpkt[] = {0x10,0x12,0x00,0x04,'M','Q','T','T',0x04,0x02,0x00,0xff,0x00,0x06,'a','b','h','i','g','r'};

byte pubpkt[]={0x30, 0x18, 0x00, 0x09 ,'s','e','n','s','o','r','s','u','b','o','k',0x10,0x09,0x09,0x09,0x01,0x01,0x01,0xDB,0xC6,0x32,0x32};

// 26len

byte subpkt[]={0x82,0x0E,0x00,0x01,0x00,0x09,'c','o','m','m','n','d','p','u','b',0x00};

char pngpkt[]={0xC0,0x00};

const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };

char relay[]= {0x0A,0x10,0x00};

char reed[]= {0x09,0x09,0x09};

char neo[]= {0x0B,0x01,0x01,0x01,0x30,0x00};

static byte pubimg[35000];

int resp;

long ping_millis = 0 , mask_millis = 0, update_millis=0, disp_millis=0;

int start_flag = 0;

int disp_count = 0;

// Execute Only once

void setup() {

Serial.begin(57600); // For Debug Port

Serial4.begin(57600); // For Enocean RX interface

SPI.begin(); // For NRF24l01

SPI.setDataMode(SPI_MODE0);

SPI.setBitOrder(MSBFIRST);

delay(100);

radio.begin(); // Defaults 1Mbps, channel 0, max TX power

dump_radio_status_to_serialport(radio.radioState()); // Should show Radio in Sleep mode

radio.setTXaddress((void*)txaddr);

// Send Default commands to relay module and RGB LED module

radio.print(relay);

radio.flush(); // Force transmit (don't wait for any more data)

delay(30);

radio.print(neo);

radio.flush(); // Force transmit (don't wait for any more data)

delay(30);

// Init OLED Sisplay

display.init();

display.flipScreenVertically();

display.setFont(ArialMT_Plain_10);

display.clear();

// Display Welcome Screen on OLED

display.drawXbm(0, 0, gr_scr_w ,gr_scr_h, gr_scr );

display.display();

delay(3000);

// Display WiFi Connecting Logo on OLED until WiFi connected

display.clear();

display.drawXbm(0, 0, cls_scr_w ,cls_scr_h, cls_scr );

display.display();

setup_wifi();

camera.begin();

Page 12: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

2

}

// Execute forever

void loop() {

// Init OpenCV and Matrix for Motion Detection

Mat img_raw(IMAGE_VW, IMAGE_HW, CV_8UC2, camera.getImageAdr());

Mat src, diff, srcFloat, dstFloat, diffFloat;

dstFloat.create(IMAGE_VW, IMAGE_HW, CV_32FC1);

dstFloat.setTo(0.0);

// Execute Forever

while(1)

{

// Detect Motion and Publish Image if motion Detected

cvtColor(img_raw, src, COLOR_YUV2GRAY_YUYV); //covert from YUV to GRAY

src.convertTo(srcFloat, CV_32FC1, 1 / 255.0);

addWeighted(srcFloat, 0.25, dstFloat, 0.75, 0, dstFloat, -1);

absdiff(srcFloat, dstFloat, diffFloat);

diffFloat.convertTo(diff, CV_8UC1, 255.0);

cv:Scalar tempVal = mean( diff );

float myMAtMean = tempVal.val[0];

if((myMAtMean>MOTION_TH) && (start_flag >= 17) && (millis()-mask_millis >= MASK_INTERVAL))

{

mask_millis = millis();

delay(100);

Serial.println("Motion Detected");

display.clear();

display.drawXbm(0, 0, cm_scr_w ,cm_scr_h, cm_scr );

display.display();

capture_send();

}

else if (start_flag <= 20)

{

start_flag++;

}

if(millis()-disp_millis >= DISP_INTERVAL)

{

disp_millis = millis();

if(disp_count > 3)disp_count=0;

if(disp_count == 0) disp_sw();

else if(disp_count == 1) disp_dr();

else if(disp_count == 2) disp_tp();

else if(disp_count == 3) disp_tr();

disp_count++;

}

// Ping Broker at every PING_INTERVAL ms

if(millis()-ping_millis >= PING_INTERVAL)

{

ping_millis = millis();

delay(100);

Serial.println("ping");

resp = wifi.send(0,pngpkt, 2);

}

// Publish Sensor Updates to Broker at every UPDATE_INTERVAL

if(millis()-update_millis >= UPDATE_INTERVAL)

{

update_millis = millis();

Serial.println("pubmsg");

Page 13: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

3

resp = wifi.send(0,pubpkt, 26);

Serial.print("Responce is ");

Serial.print(resp);

Serial.println();

if(resp == 0)

{

reconnect_broker();

}

}

respond_msg();

check_enocean_nrf();

delay(50);

}

}

// Function to Capture image and Publish to "imagesub" topic

void capture_send(void)

{

unsigned int len;

unsigned int point = 0;

delay(10);

pubimg[0] = 0x30;

pubimg[1] = 0x84;

pubimg[2] = 0x2A;

pubimg[3] = 0x00;

pubimg[4] = 0x08;

pubimg[5] = 'i';

pubimg[6] = 'm';

pubimg[7] = 'a';

pubimg[8] = 'g';

pubimg[9] = 'e';

pubimg[10] = 's';

pubimg[11] = 'u';

pubimg[12] = 'b';

point = 13;

// read from the camera until there's nothing else in it:

size_t size = camera.createJpeg();

delay(100);

uint8_t* adr = camera.getJpegAdr();

for (size_t i = 0; i < size; i++) {

pubimg[point]=*adr;

adr++;

point++;

}

delay(100);

len = size+10;

pubimg[1]=(len%128)|0x80;

pubimg[2]=(len/128);

// read from the file until there's nothing else in it:

Serial.print("pubimg : ");

//resp = wifi.send(0,pubimg,5383);

resp = wifi.send(0,pubimg,len+3);

Serial.println(resp);

if(resp == 0)

{

reconnect_broker();

}

}

// Function to setup WiFi and Connect to MQTT Broker

Page 14: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

4

void setup_wifi(void)

{

delay(1000);

Serial.print("Connecting Wi-Fi..");

wifi.connect(WIFI_SSID, WIFI_PW);

Serial.println("done");

Serial.println(wifi.getIPAddress());

delay(1000);

Serial.print("Broker :");

resp = wifi.open("TCP",0,BROKER, 1883); // Our own Amazon AWS Broker

Serial.println(resp);

delay(100);

Serial.print("Broker : ");

resp = wifi.send(0,connectpkt, 20);

Serial.println(resp);

delay(100);

Serial.print("Sub : ");

resp = wifi.send(0,subpkt, 16);

Serial.println(resp);

delay(100);

}

// Function to print NRF24l01 Status on Debug port

void dump_radio_status_to_serialport(uint8_t status)

{

Serial.print("Enrf24 radio transceiver status: ");

switch (status) {

case ENRF24_STATE_NOTPRESENT:

Serial.println("NO TRANSCEIVER PRESENT");

break;

case ENRF24_STATE_DEEPSLEEP:

Serial.println("DEEP SLEEP <1uA power consumption");

break;

case ENRF24_STATE_IDLE:

Serial.println("IDLE module powered up w/ oscillators running");

break;

case ENRF24_STATE_PTX:

Serial.println("Actively Transmitting");

break;

case ENRF24_STATE_PRX:

Serial.println("Receive Mode");

break;

default:

Serial.println("UNKNOWN STATUS CODE");

}

}

// Function to Check incoming data from Enocean Receiver and respond to NRF24l01

void check_enocean_nrf(void)

{

int i=0;

unsigned char packet[50];

while(Serial4.available()>0)

{

delay(3);

if(i==0)Serial.print("Rx Packet:");

Page 15: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

5

char rxb= Serial4.read();

if(i!=0)

{

packet[i] = rxb;

i++;

}

if (rxb == 0x55)

{

i=0;

packet[i] = rxb;

i++;

delay(60);

}

}

if(i != 0)

{

Serial.println(" ");

if(packet[2] == 0x07)

{

if((packet[6] == 0xF6) && (packet[7]!=0x00))

{

Serial.println("Sensor Type = Rocker Switch");

Serial.print("Payload = 0x");

Serial.print(packet[7],HEX);

if(packet[7] == 0x50 ) relay[1]^=0x01;

else if(packet[7] == 0x10 ) relay[1]^=0x02;

else if(packet[7] == 0x70 ) relay[1]^=0x04;

else if(packet[7] == 0x30 ) relay[1]^=0x08;

pubpkt[15] = relay[1];

disp_sw();

radio.print(relay);

radio.flush(); // Force transmit (don't wait for any more data)

delay(500);

}

if(packet[6] == 0xD5)Serial.println("Sensor Type = Reed Switch");

{

if(packet[7]==0x09)Serial.println("Switch = Closed");

else if(packet[7]==0x08)Serial.println("Switch = Open");

else Serial.println(" ");

if(packet[11] == 0x99) {reed[0] = packet[7]; pubpkt[16] = packet[7];}

else if(packet[11] == 0x1D) {reed[1] = packet[7]; pubpkt[17] = packet[7];}

else if(packet[11] == 0x65) {reed[2] = packet[7]; pubpkt[18] = packet[7];}

disp_dr();

}

Serial.print("Source ID = 0x");

Serial.print(packet[8],HEX);

Serial.print(packet[9],HEX);

Serial.print(packet[10],HEX);

Serial.println(packet[11],HEX);

Serial.print("RSSI = -");

Serial.print(packet[18],DEC);

Serial.println("dBm");

}

if(packet[2] == 0x0A)

{

if(packet[8] == 0x00)

{

float temp=0;

Serial.println("Sensor Type = Temperature Sensor");

Serial.print("Payload = 0x");

Page 16: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

6

Serial.print(packet[9],HEX);

temp = (255.0 - (float)packet[9])*40.0/255.0;

Serial.print("\tTemperature = ");

Serial.print(temp - 2.0);

Serial.println(" Degree Celcius");

Serial.print("Source ID = 0x");

Serial.print(packet[11],HEX);

Serial.print(packet[12],HEX);

Serial.print(packet[13],HEX);

Serial.println(packet[14],HEX);

Serial.print("RSSI = -");

Serial.print(packet[21],DEC);

Serial.println("dBm");

if(packet[14] == 0xCF) pubpkt[24] = packet[9];

else if (packet[14] == 0xE8) pubpkt[25] = packet[9];

disp_tp();

}

else

{

float temp=0;

Serial.println("Sensor Type = Temperature & Moisture Sensor");

Serial.print("Payload = 0x");

Serial.print(packet[8],HEX);

temp = ((float)packet[8])*100.0/255.0;

Serial.print("\tMoisture = ");

Serial.print(temp);

Serial.println(" %");

Serial.print("Payload = 0x");

Serial.print(packet[9],HEX);

temp = ((float)packet[9])*40.0/255.0;

Serial.print("\tTemperature = ");

Serial.print(temp);

Serial.println(" Degree Celcius");

Serial.print("Source ID = 0x");

Serial.print(packet[11],HEX);

Serial.print(packet[12],HEX);

Serial.print(packet[13],HEX);

Serial.println(packet[14],HEX);

Serial.print("RSSI = -");

Serial.print(packet[21],DEC);

Serial.println("dBm");

pubpkt[22] = packet[8];

pubpkt[23] = packet[9];

disp_tr();

}

}

Serial.println("pubmsg");

resp = wifi.send(0,pubpkt, 26);

Serial.print("Responce is ");

Serial.print(resp);

Serial.println();

if(resp == 0)

{

reconnect_broker();

}

delay(100);

packet[i] = 0;

i=0;

}

}

Page 17: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

7

// Check for Incoming MQTT Message if any and respond

void respond_msg(void)

{

while(wifi.readable())

{

char rxbuffer[]={" "};

delay(10);

resp = wifi.recv(0,rxbuffer, sizeof rxbuffer);

if(rxbuffer[13] != ' ')

{

Serial.print("msg = ");

Serial.print(rxbuffer[13],HEX);Serial.print(',');

Serial.print(rxbuffer[14],HEX);Serial.print(',');

Serial.print(rxbuffer[15],HEX);Serial.print(',');

Serial.println(rxbuffer[16],HEX);

relay[1] = rxbuffer[13]; pubpkt[15]=rxbuffer[13];

neo[1] = rxbuffer[14]; pubpkt[19]=rxbuffer[14];

neo[2] = rxbuffer[15]; pubpkt[20]=rxbuffer[15];

neo[3] = rxbuffer[16]; pubpkt[21]=rxbuffer[16];

radio.print(relay);

radio.flush(); // Force transmit (don't wait for any more data)

delay(30);

radio.print(neo);

radio.flush(); // Force transmit (don't wait for any more data)

delay(30);

Serial.println("pubmsg");

resp = wifi.send(0,pubpkt, 26);

Serial.print("Responce is ");

Serial.print(resp);

Serial.println();

if(resp == 0)

{

reconnect_broker();

}

delay(100);

}

}

}

// Function to Reconnect MQTT Broker

void reconnect_broker(void)

{

wifi.close(0,2);

delay(100);

Serial.print("Reconnect : ");

resp = wifi.open("TCP",0,BROKER, 1883);

Serial.println(resp);

delay(100);

Serial.print("Broker : ");

resp = wifi.send(0,connectpkt, 20);

Serial.println(resp);

delay(100);

Serial.print("Sub : ");

resp = wifi.send(0,subpkt, 16);

Serial.println(resp);

}

// Function to display Relay Status on OLED

void disp_sw(void)

{

Page 18: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

8

display.clear();

if((pubpkt[15] & 0x01) == 0x01){display.drawXbm(0, 0, on_scr_w ,on_scr_h, on_scr );}

else {display.drawXbm(0, 0, of_scr_w ,of_scr_h, of_scr );}

if((pubpkt[15] & 0x02) == 0x02){display.drawXbm(64, 0, on_scr_w ,on_scr_h, on_scr );}

else {display.drawXbm(64, 0, of_scr_w ,of_scr_h, of_scr );}

if((pubpkt[15] & 0x04) == 0x04){display.drawXbm(0, 32, on_scr_w ,on_scr_h, on_scr );}

else {display.drawXbm(0, 32, of_scr_w ,of_scr_h, of_scr );}

if((pubpkt[15] & 0x08) == 0x08){display.drawXbm(64, 32, on_scr_w ,on_scr_h, on_scr );}

else {display.drawXbm(64, 32, of_scr_w ,of_scr_h, of_scr );}

display.display();

}

// Function to display Door Reed Switch Status on OLED

void disp_dr(void)

{

display.clear();

display.drawXbm(0, 0, dr_scr_w ,dr_scr_h, dr_scr );

display.setFont(ArialMT_Plain_16);

display.setTextAlignment(TEXT_ALIGN_LEFT);

if(pubpkt[16]==0x09){display.drawString(42, 0, "D1 LOCK");}

else {display.drawString(42, 0, "D1 OPEN");}

if(pubpkt[17]==0x09){display.drawString(42, 21, "D2 LOCK");}

else {display.drawString(42, 21, "D2 OPEN");}

if(pubpkt[18]==0x09){display.drawString(42, 42, "D3 LOCK");}

else {display.drawString(42, 42, "D3 OPEN");}

display.display();

}

// Function to display Plant Status on OLED

void disp_tr(void)

{

float m,t;

char bufm[10];

char buft[10];

m = ((float)pubpkt[22])*100.0/255.0;

t = ((float)pubpkt[23])*40.0/255.0;

snprintf(bufm,10,"M = %d %%",(int)m);

snprintf(buft,10,"T = %d C",(int)t);

display.clear();

display.drawXbm(0, 0, tr_scr_w ,tr_scr_h, tr_scr );

display.setFont(ArialMT_Plain_16);

display.setTextAlignment(TEXT_ALIGN_LEFT);

display.drawString(38, 10, bufm);

display.drawString(38, 38, buft);

display.display();

}

// Function to display Temperature sensor Status on OLED

void disp_tp(void)

{

float t1,t2;

char buft1[10];

char buft2[10];

t1 = (255.0 - (float)pubpkt[24])*40.0/255.0;

t2 = (255.0 - (float)pubpkt[25])*40.0/255.0;

snprintf(buft1,10,"T1 = %d C",(int)t1);

snprintf(buft2,10,"T2 = %d C",(int)t2);

display.clear();

display.drawXbm(0, 0, tp_scr_w ,tp_scr_h, tp_scr );

display.setFont(ArialMT_Plain_16);

Page 19: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age1

9

display.setTextAlignment(TEXT_ALIGN_LEFT);

display.drawString(38, 2, buft1);

display.drawString(38, 21, buft2);

display.drawString(38, 42, "T3 = xx C");

display.display();

}

Attachments:

Source codes for GR Lychee and Android App with Apk file

Thanks,

Team : IoT Geek

Page 20: YouTube Link - Renesas Electronicstool-cloud.renesas.com/edDir/files/smart_home.pdf · 2019-01-07 · Team Id: IoT Geek Video: Team Members: Abhijit Nathwani & Jaydev Dave Page 3

Team Id: IoT Geek Video: https://www.youtube.com/watch?v=jkyPx_DUooA

Team Members: Abhijit Nathwani & Jaydev Dave P

age2

0