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.
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.
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.
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.
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.
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
Press the button to send the message via
Configure WeChat miniprogram in the console first. Set the server up.
Add server side scripts for receiving the data and store it in database.
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
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.
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.
Handling errors in miniprogram.
Bind enter key in python client to render a task as complete. Add
[OK] to the start of the message.
User input sanitizing. Trim the input and remove all new lines before sending.
Add recent message list view to miniprogram, so the assistant can view the recent message they sent.
Reverse the recent message list, more recent message stays on top.
Prevent empty messages to be sent.
Sort the message list on python client. Put finished tasks on top, and unfinished below them.
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.
Fix index out of range problem.
Dig into python client
fail to do name resolution error.
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.
release_conn each time after request.
Use green for finished tasks and black for unfinished tasks in miniprogram.
Got my 30-meter long network cable. Connect the raspberry pi to router physically.
It’s been two days, no errors occurred. The network problem is solved.
dwservice to raspberry pi to have a remote desktop login to the pi so I can manage everything anywhere.
oray to get LAN penetration, and set up ssh server on pi so I can ssh to pi anywhere I want.
Add separate line to python client so finished tasks and unfinished ones are better distinguished.
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
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
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.
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.
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.
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.
select the previous task.
select the next task.
finish the current selected task.
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.
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.
Time to think about the remote case. Bought some tools to make myself.
All the stuff will arrive tomorrow.
I’ve got my perfboards