Background
It's getting messy when the warehouse is separated to another location. We used to pack all the products right at the store. So when the sales assistants need to communicate with the delivery staff.
The Problem
Phone Calls and Voice Messages
So, each time a sales assistant's got some information to inform the delivery staff, be it either a customer changes her shipping address, or some customer wants additional parts in their package, they call the delivery staff, or send them a voice message through WeChat.
Reaching for the phone is not ideal. Waiting for a phone call to get through takes up to 20 seconds. And listening to voice messages are more time consuming, if interrupted, you have to start all over again.
Message Loss
Sometimes the sales assistant will also send some important message in the chat group so every delivery staff can see it. But when there're lots of messages and the delivery staff failed to read the first few important ones in time, the messages just get lost in the the stack, and later things might go wrong.
Solution
Problem 1
To solve the problem. I first purchased a pair of 4G network walkie talkie. They are able to cover the range of a whole country. Where there is 4G signal, they can work just fine. Unlike radio walkie talkies, they won't work on long distances and behind thick walls.
When someone has important message to share, they just pick up the device and hail each other.
Simple and clear.
Problem 2
For the message loss problem, I have to design a small notification system. I have this spare TV back at home, which I can use as a digital notification board to display important messages from the sales assistant.
I just need a portal for the assistants to send messages, and a server to store the messages, and a client running in the warehouse to display the messages.
Then, hook my raspberry pi with my TV, everything's taken care of.
Get the Hands Dirty
Let the fun begin.
Log 08-29-2021
Created project DMaT
as for Don't Miss a Thing
.
Think about the portal to send the messages. WeChat miniprogram is my first option. Integrated into WeChat, easy access, just swip down to use.
Just need an input box
, and a send button
.
Press the button to send the message via POST
request.
Configure WeChat miniprogram in the console first. Set the server up.
Add server side scripts for receiving the data and store it in database.
Log 08-30-2021
Create a new database for this project. And add a table for storing the messages.
let's encrypt
my server to https.
Test if WeChat miniprogram can connect to my server.
Plan out the client side UI.
Nail the UI for today. Same old python Tkinter
.
I need a listbox
to display the messages, and a button
to render the message/task as completed. Pretty much like a TODO list.
UI is done.
Log 08-31-2021
GET
request to retrieve the message from server.
Change UI to full screen.
Add update message script to server.
Default showing all tasks, finished, or unfinished.
Log 09-01-2021
Handling errors in miniprogram.
Bind enter key in python client to render a task as complete. Add [OK]
to the start of the message.
Log 09-02-2021
User input sanitizing. Trim the input and remove all new lines before sending.
Log 09-03-2021
Add recent message list view to miniprogram, so the assistant can view the recent message they sent.
Log 09-04-2021
Reverse the recent message list, more recent message stays on top.
Prevent empty messages to be sent.
Log 09-05-2021
Sort the message list on python client. Put finished tasks on top, and unfinished below them.
Log 09-06-2021
Change get message request condition to unfinished tasks and finished tasks whose finished time is within 24 hours til request time.
Add new column denoting finished time to table.
Log 09-07-2021
Field test.
Fix index out of range problem.
Log 09-08-2021
Field test.
Dig into python client ProtocolError
, MaxRetry
, or fail to do name resolution
error.
Log 09-09-2021
Those python client problems may be caused by network issues.
The USB wireless dongle I got has a broken antenna.
Will try fix this tomorrow.
Log 09-10-2021
Call release_conn
each time after request.
Use green for finished tasks and black for unfinished tasks in miniprogram.
Log 09-13-2021
Field test.
Got my 30-meter long network cable. Connect the raspberry pi to router physically.
Keep testing.
Log 09-15-2021
It's been two days, no errors occurred. The network problem is solved.
Log 09-18-2021
Add dwservice
to raspberry pi to have a remote desktop login to the pi so I can manage everything anywhere.
Log 09-19-2021
Use oray
to get LAN penetration, and set up ssh server on pi so I can ssh to pi anywhere I want.
Log 09-20-2021
Add separate line to python client so finished tasks and unfinished ones are better distinguished.
Log 09-21-2021
I don't have keyboard and mouse connected to my pi. So I have to use dwservice to see the remote desktop and click the finished button there. Not so good.
Thinking about adding a remote control to my pi. Not using jumper wires to connect the buttons to the pi, but I can just use wifi to send signals to select tasks and complete them.
First thought was Zigbee
or bluetooth
, but I may be complicating things up. Just raw socket will do, because the remote and pi are in the same network.
For the remote, I choose NODEMCU
, and ESP8266
based chip which is wifi capable. Perfectly suits my need.
My thought here is to program the NODEMCU
, whenever I press a button, send a predefined signal/command through socket. And on the python side, receive the signal/command, and do stuff accordingly, like select the next task and finished it.
I'm going to have 4 buttons, to simulate 4 keys. Up
, Down
, Tab
, and Finish
. Up
and Down
are for selecting different messages. Tab
is for getting the focus back to the messages/tasks.
I have a new raspberry pi 4B on delivery. Going to code tomorrow, and I can test it when the new pi arrives.
Log 09-22-2021
Power up the bread board with a two battery pack case.
The goal today is to power up the MCU, connect to some wifi network and simulate a socket signal/message/command to a python socket.
Someone moved my cable for the node. Took me half an hour to find a new one.
Now, connecting to wifi is not a problem. The attached a green LED to the bread board, when the node successfully connects to my wifi, it lights up the LED.
Next step, write a simple python socket to receive data transmission.
Have done testing C socket client and server on my BSD.
Next step is to write python sockets.
Not able to write code just now, instead I made a external 3V power supply with the battery pack and jumper wires. This is going to be the power source for the remote.
Have to test the power supply on the chip.
Not seem to work. Have to check the spec.
NodeMCU can handle up to 16V power supply through VIN
pin. It's got its own regulator integrated. So I've got this 9V battery, which now can be the power supply.
I have successfully powered up the node with the 9V battery. Green light is up, wifi connected.
Python socket server is done. And using C code to send command to python socket both from localhost and peer in the same network range are working as expected. Python really makes life easy 😀
Integrate the four buttons, test for HIGH LOW pulse on node.
The prototype has done. Now I can press different buttons, the program can then choose to send different commands accordingly.
Combine that to socket now. Send commands to python socket server when a button is pressed.
Log 09-25-2021
Fire up the socket server in python client.
Need to put it in another thread or process.
Start a new thread to bootstrap a socket server. After a little fumbling, I nailed the multithread client socket thing. It'll now start a new thread for a new connection.
This picture shows the nodemcu connects to the python program, and send different commands on button click.
Now, it's time to use pynput
to simulate the real keyboard event.
Command up
to select the previous task
.
Command down
to select the next task
.
Command finish
to finish the current selected task
.
Command focus
to change focus back to task listbox
.
C socket failed. Because arduino-builder
handles libraries pretty badly. Failed to find sys/socket.h
. But if I copy all the header file to sdk/include
folder, some conflict may occur and the compilation would fail.
After a little digging, node's got its own like socket wrapper called WiFiClient
, which has done all the heavy lifting, just use it to connect to the server, and call write
to send command to server.
Now, its all done.
Log 09-27-2021
With what I have now, I can use this prototype to control the program in my warehouse. But what I want is some kind of thing that looks more like a remote. A rough idea here is to solder everything onto a proto board, pack everything together to make a "remote".
By the way, my new Raspberry Pi 4 had arrived. It's an 8G memory beauty.
Log 09-28-2021
Time to think about the remote case. Bought some tools to make myself.
All the stuff will arrive tomorrow.
Log 09-30-2021
I've got my perfboards