Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
skruglewicz
Published © GPL3+

KitchenMind: The AI-Powered Kitchen That Thinks For You

AI-powered Kitchen Smart Inventory Assistant tracks your food, suggests recipes, and reduces food waste.

AdvancedFull instructions providedOver 1 day676

Things used in this project

Hardware components

UNIHIKER - IoT Python Programming Single Board Computer with Touchscreen
DFRobot UNIHIKER - IoT Python Programming Single Board Computer with Touchscreen
×1
Seeed Studio SenseCap Watcher
×1
nRF7002 Development Kit
Nordic Semiconductor nRF7002 Development Kit
×1
Grove - Starter Kit for Arduino SKU 110060024
×1

Software apps and online services

Fusion
Autodesk Fusion
PCBWay CNC, 3D Printing services

Story

Read more

Custom parts and enclosures

Bottom Nordic case - step file

This is the bottom CNC printing file that I submitted to PCBWay.com for Manufacturing.

TOP Nordic case - step file

This is the top part of the case That was created in Fusion360

Nordic PCB board temp[late

PCB board used as a temp[late to create the Nordic case in Fusion360

Schematics

apple_QKw1fATzC8.png

apple.png file used in KincenMind Index.py

pantry_GrG7FeXdoA.png

pantry.png file used in index.py

nordic board

the nRf52840 - DK

Code

index.py MQTT TEST Unihiker

C/C++
# Example on how to use the paho mqtt python client
# establishing a two way protocol with the MQTT lesson 4 example 1 from DevAcadamy on the nRF7002DK
#
# Example on how to use the paho mqtt python client
# establishing a two way protocol with the MQTT lesson 4 example 1 from DevAcadamy on the nRF7002DK


# ## Import needed packages


import paho.mqtt.client as mqtt
import ssl
import time


version = '3' # or '3' '5'
mytransport = 'tcp' # or 'tcp' 'websockets'


# ## Choose which protocol version and create a client object
if version == '5':
    client = mqtt.Client(client_id="myPy",
                         transport=mytransport,
                         protocol=mqtt.MQTTv5)
if version == '3':
    client = mqtt.Client(client_id="myPy",
                         transport=mytransport,
                         protocol=mqtt.MQTTv311,
                         clean_session=True)


# ## Define the callbacks
import mycallbacks
client.on_connect = mycallbacks.on_connect;
client.on_message = mycallbacks.on_message;
client.on_publish = mycallbacks.on_publish;
client.on_subscribe = mycallbacks.on_subscribe;


# ## Connect to the broker i have tested with 4 MQTT brokers 


# broker = 'pf-bh4naesxw46j1nptlbr5.cedalo.cloud' # eg. choosen-name-xxxx.cedalo.cloud
# myport = 1883


#broker = '192.168.1.165' # SIoT
##port = 8080
#yport = 1883


broker = 'broker.hivemq.com' # HIVEMQ Unsecured
myport = 1883


#broker = 'test.mosquitto.org' # test.mosquitto.org
#myport = 1883


if version == '5':
    from paho.mqtt.properties import Properties
    from paho.mqtt.packettypes import PacketTypes 
    properties=Properties(PacketTypes.CONNECT)
    properties.SessionExpiryInterval=30*60 # in seconds
    client.connect(broker,
                   port=myport,
                   clean_start=mqtt.MQTT_CLEAN_START_FIRST_ONLY,
                   properties=properties,
                   keepalive=60);


if version == '3':
    #client.connect(broker,keepalive=60); # SIoT does not need a port
    client.connect(broker,port=myport,keepalive=60);


client.loop_start();


# ## Subscribe to a topic
mytopic = 'skrug/nrf7002DK/publish/button/topic99'
#mytopic = 'SmartAgricultureIoTSystem/Soil_moisture_value'
client.subscribe(mytopic,0);


# ## Publish to the topic
from paho.mqtt.properties import Properties
from paho.mqtt.packettypes import PacketTypes 
properties=Properties(PacketTypes.PUBLISH)
properties.MessageExpiryInterval=30 # in seconds


pubtopic = 'skrug/nrf7002DK/subscribe/led/topic99'


#BLINK the LED
LED = 'LED1OFF'


while True:
    client.publish(pubtopic,LED,2,properties=properties);
    time.sleep(5)
    LED = 'LED1ON'
    client.publish(pubtopic,LED,2,properties=properties);
    time.sleep(5)
    LED = 'LED1OFF'


    # ## Finally unscubscribe and close the connection
    #client.unsubscribe(mytopic);
    #client.disconnect();

callbacks.py MQTT TEST Unihiker

C/C++
MQTT callback functions imported by index.py
from datetime import datetime as dt
from paho.mqtt.client import connack_string as ack


def on_connect(client, userdata, flags, rc, v5config=None):
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Connection returned result: "+ack(rc))


def on_message(client, userdata, message,tmp=None):
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Received message " + str(message.payload) + " on topic '"
        + message.topic + "' with QoS " + str(message.qos))


def on_publish(client, userdata, mid,tmp=None):
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Published message id: "+str(mid))
    
def on_subscribe(client, userdata, mid, qos,tmp=None):
    if isinstance(qos, list):
        qos_msg = str(qos[0])
    else:
        qos_msg = f"and granted QoS {qos[0]}"
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Subscribed " + qos_msg) 

KitchenMind Uihiker - mycallbacks.py

Python
Callback Functions for the MQYY code in index.py
from datetime import datetime as dt
from paho.mqtt.client import connack_string as ack
import shared


def on_connect(client, userdata, flags, rc, v5config=None):
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Connection returned result: "+ack(rc))

def on_message(client, userdata, message,tmp=None):
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Received message " + str(message.payload) + " on topic '"
        + message.topic + "' with QoS " + str(message.qos))
    # set temp variable
    shared.mytemp = message.payload
    print(" mytemp " + str(shared.mytemp))


def on_publish(client, userdata, mid,tmp=None):
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Published message id: "+str(mid))
    
def on_subscribe(client, userdata, mid, qos,tmp=None):
    if isinstance(qos, list):
        qos_msg = str(qos[0])
    else:
        qos_msg = f"and granted QoS {qos[0]}"
    print(dt.now().strftime("%H:%M:%S.%f")[:-2] + " Subscribed " + qos_msg)    

KitchenMind Uihiker -shared.py

Python
shared variable used in index.py and mycallbacks.py
# shared.py
mytemp = 0; # set global var for temp

KitchenMind Uihiker - index.py

Python
Main code to run on the Unihiker
#!/usr/bin/env python
# coding: utf-8

# # kITCHENmind RUNNING ON THE UNIHIKER
# SUBSCRIBES TO TOPIC  'skrug/pantry1/temp'

# ## Import needed packages

import paho.mqtt.client as mqtt
import ssl
import time
from unihiker import GUI  # Importing the GUI module from the unihiker library
import time  # Importing the time library
import shared

 ## setup MQTT
version = '3' # or '3' '5'
mytransport = 'tcp' # or 'tcp' 'websockets'


# ## Choose which protocol version and create a client object

if version == '5':
    client = mqtt.Client(client_id="myPy",
                         transport=mytransport,
                         protocol=mqtt.MQTTv5)
if version == '3':
    client = mqtt.Client(client_id="myPy",
                         transport=mytransport,
                         protocol=mqtt.MQTTv311,
                         clean_session=True)



import mycallbacks
client.on_connect = mycallbacks.on_connect;
client.on_message = mycallbacks.on_message;
client.on_publish = mycallbacks.on_publish;
client.on_subscribe = mycallbacks.on_subscribe;

# ## Connect to the broker

broker = 'broker.hivemq.com' # HIVEMQ Unsecured
myport = 1883

if version == '5':
    from paho.mqtt.properties import Properties
    from paho.mqtt.packettypes import PacketTypes 
    properties=Properties(PacketTypes.CONNECT)
    properties.SessionExpiryInterval=30*60 # in seconds
    client.connect(broker,
                   port=myport,
                   clean_start=mqtt.MQTT_CLEAN_START_FIRST_ONLY,
                   properties=properties,
                   keepalive=60);
if version == '3':
    #client.connect(broker,keepalive=60); # SIoT does not need a port
    client.connect(broker,port=myport,keepalive=60);

client.loop_start();

# ## Subscribe to a topic
mytopic = 'skrug/pantry1/temp'
client.subscribe(mytopic,2);

# ## Publish to the topic NOT USED YET but will implement the other end
from paho.mqtt.properties import Properties
from paho.mqtt.packettypes import PacketTypes 
properties=Properties(PacketTypes.PUBLISH)
properties.MessageExpiryInterval=30 # in seconds
pubtopic = 'skrug/nrf7002DK/subscribe/led/topic99'
#BLINK the LED
LED = 'LED1OFF'

## set up the display and define callbacks for buttons
gui = GUI()  # Instantiating the gui object

# Displaying the background image
#img = gui.draw_image(w=240, h=320, image='img/stop1.png')
img = gui.draw_image(w=240, h=320, image='img/pantry.png')

# Defining callback functions
def click_A():  # Define the operation when button A is clicked - image switch
    img.config(w=240, h=380, image='img/apple.png')

    #get room1 from MQTT
    room1 = 'Pantry1'
    text1.config(text=room1)

    # get temp from mqtt
    pantry1_temp = shared.mytemp
    print(" mytemp " + str(pantry1_temp))
    text_value.config(text=pantry1_temp)


def click_B():  # Define the operation when button B is clicked - image switch
    #clear out the temp text boxes
    img.config(w=240, h=320, image='img/pantry.png')
    
    room1 = ''
    text1.config(text=room1)

    pantry1_temp = 0;
    text_value.config(text=pantry1_temp)



# Display buttons
'''Display buttons and set their functions triggered by clicking'''
button_A = gui.add_button(x=50, y=260, w=70, h=40, text="ADD", onclick=click_A)
button_B = gui.add_button(x=140, y=260, w=70, h=40, text="STOP", onclick=click_B)


# Draw filled rectangles and display text inside them
gui.fill_rect(x=45, y=35, w=95, h=30, color="white")
gui.fill_rect(x=148, y=35, w=55, h=30, color="white")
text1 = gui.draw_text(x=48, y=36, color="black", text='') #room1 value
text_value = gui.draw_text(x=160, y=36, color="black", text="0") # Display initial Tempreture

print(" mytemp " + str(shared.mytemp))
save_temp = shared.mytemp

while True:
    if save_temp != shared.mytemp:
        save_temp = shared.mytemp
        click_A()
        

    time.sleep(1)  # Wait for 1 second

    #client.publish(pubtopic,LED,2,properties=properties);
    #time.sleep(5)
    #LED = 'LED1ON'
    #client.publish(pubtopic,LED,2,properties=properties);
    #time.sleep(5)
    #LED = 'LED1OFF'



    # ## Finally unscubscribe and close the connection
    #client.unsubscribe(mytopic);
    #client.disconnect();

Credits

skruglewicz
26 projects • 15 followers
I am now a retired Senior Software Engineer with a Bachelor’s of Science Degree in Computer Science from Boston University.
Contact

Comments

Please log in or sign up to comment.