This is a whole new take on my other post about PiFace CAD hat.
This is more about the actual node.
The node code
But I have modified it for reasons I hope to explain shortly.
So I am nearly making a node. But I don't want to really claim that. I am just trying to understand how an existing node works because I have an upcoming need for it to do a lot more than was intended.
At the start I used the node to play with my PiFace HAT. It worked in it allowed me to send messages to the screen.
And it did that. Though how I did it was really a long trip.
I would send a message, parse the message and use a .... script to run a python script to then parse the message and print it on the screen.
This was a long time ago and the messages were simple enough. It seemed to work.
Time has moved on.
But given the node's README file says:
To work with lcd node: Here's how to send data to this node.
ROW,COL:YOUR TEXT
for clear lcd send
1,1:
to the node to clear lcd.
Be careful not to use any spaces in any of these commands.
Alas there was a problem that the code as given didn't allow positioning of the text on the screen.
That took me a long time to work out, but I did finally get it working to do that.
(I'll leave out some stuff to what happened as I am not exactly sure now myself.)
Now we get to "now", and I am really wanting to use this node. Though it may be easier for me to actually make a node myself. Not sure.
So, I want to position text on the screen and it works. (Or so I remember)
Now, I want to send a more complex message - like the time, or date.
In the form:
08:44:33 for the time
and
29/07/20 for the date
So, the time option just failed miserably. I can't send a :
in the message because when the real message is parsed it uses a :
as a delimiter.
I went into the code and changed the delimiter from :
to @
. I don't need any @
on the display.
So then I could print the time on the screen.
The date caused a bit of trouble with the /
, but using {{{ }}}
rather than {{ }}
solved that problem. (Thanks @zenofmud)
Two down, more to come.
All of this is/was being tested initially from the CLI running in the node's directory.
So the command would be:
python pfc_lcd/py 5,1@08:44:33
and it would display at that position.
I wrote a flow to allow me to inject the date and time (separately) and they worked. (But there's a Gremlin in that story. I'll get back to that soon.)
Then I went on to send stuff like:
python pfc_lcd.py 2,2@"Hello there"
and that too would work.
It all came crashing down when I made an inject
node to send that message.
All I see is "Hello/#
on the screen.
WHY?
Looking into the pfc_lcd.js
files I see this line:
text = msg.payload.replace(" ", "#/@$%");
And looking a bit harder at the github page there is this:
Be careful not to use any spaces in any of these commands.
Ah! Ok. So it wasn't just like between the positions, or the :
, but anywhere in the line.
But hang on! That doesn't make sense!
I have my CLI open in: pi@PIFACE:~/.node-red/node_modules/node-red-contrib-pifacecad $
and am running the python script.
I get that if I do:
python pfc_lcd.py 1,1@Hello there
all I will see is Hello
But if I enter:
pythono pfc_lcd.py 1,1@"Hello there"
I see Hello there
So what's going on?
Other things I did / tried:
Statusquo if I make the message Hello_there
it works. Yeah, no big deal in that.
Then I delete the line:
text = msg.payload.replace(" ", "#/@$%");
Still not getting what I want.
- The other Gremlin I mentioned.
It says:
for clear lcd send
1,1:
to the node to clear lcd.
Tautological, I agree, but......
I send:
1,1@Message
Then send:
2,2@Another
The screen is wiped when the second message is sent.
I can't see how/why this is happening.
Digging into the python code I see:
else:
cad.lcd.clear()
Hmmmmmm..... Ok. So somehow this else
is being activated.
Deleting the two lines has no effect on the display being wiped when the next message is sent.
Please, if you are still reading: Help me.
update:
I restarted (actually that didn't work. I had to stop it and start it.) Node-Red and I am getting an error:
ReferenceError: text is not defined at PFC_LiquidCrystal._inputCallback (/home/pi/.node-red/node_modules/node-red-contrib-pifacecad/pfc_lcd.js:8:53)
Into which I am looking now.
I'm guessing that is: line:column.
(But that aside, if I run the pfc_lcd.py
file from the CLI, it works. No errors.)
Further update:
Rebooting the machine and all that.
This is the error I see in Node-Red:
Error: Command failed: python2 "/home/pi/.node-red/node_modules/node-red-contrib-pifacecad/pfc_lcd.py" 1,1@HelloTraceback (most recent call last): File "/home/pi/.node-red/node_modules/node-red-contrib-pifacecad/pfc_lcd.py", line 29, in <module> raise TypeError("The entered text is not correct")TypeError: The entered text is not correct
Ok line 29.
That is the one that is basically:
except:
raise TypeError("The entered text is not correct")
But I don't know if it means PHYSICALLY line 29, or the 29'th line of valid code. (Excluding comments)
The stuff I am sending into it is exactly the same as always. Just now it is deciding it is "not correct")