leommxj / mdp_commander

The Unlicense
17 stars 0 forks source link

Amazing project, but RecvError #1

Closed market84 closed 7 months ago

market84 commented 8 months ago

Hi Leopold,

Amazing piece of reverse engineering and coding! Indeed the P906 is more suitable for controlling from a PC, so I am grateful for your effort on this. I would love to use your code for my own html interface using a websocket, which I already have for a 3 channel power supply linked with modbus (I am happy to share it with you if I get your code working).

Unfortunately, I keep getting the mdp.RecvError: b'' (see full error output below). This after I checked everything, I think. My nrf24l01 is working and correctly wired (I checked it with a color led light bulb), I use the correct id code, channel and address of my P906 and the nrf24 module is on top of the P906 like in your video. I tried both the lib code and CLI, with same result.

Am I overseeing something? Can you please suggest more checks I could do to find the cause of the error? This is the full error output:

File "d:\xxx\Miniware 1\lib.py", line 5, in p.connect() File "d:\xxx\Miniware 1\mdp.py", line 356, in connect self.getGainOffset() File "d:\xxx\Miniware 1\mdp.py", line 274, in getGainOffset _, d = self.sr(genSetLedColor(self.idcode, self.led_color, self.ch_on_m01))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\xxx\Miniware 1\mdp.py", line 270, in sr p, d = self.recv() ^^^^^^^^^^^ File "d:\xxx\Miniware 1\mdp.py", line 264, in recv raise RecvError(rdata) mdp.RecvError: b''

I would be grateful if you could help me a step further.

Cheers, Mark.

market84 commented 8 months ago

Update: CLI works! I found out that I needed to add the address and channel to the command line. So where your example wrote:

python3 mdp.py set voltage 3.3 -d /dev/ttyS16 -I ${MACHINEID}

I needed to write:

python3 mdp.py set voltage 3.3 -d COM5 -a 0xC844267D72 -c 45 -I 0x853707CC

Quite happy to know that the code works with CLI on my P906. I can't get your lib code example to work for some reason. It persists in returning the mdp.RecvError: b''. There is some communication with my unit because the green led flashes, and the led color of the encoder knob changes, but the value does not change.

I think I need the lib code to integrate in my html interface, so it would be great if you could give me some suggestions on how to get it to work. Thanks again Leopold!

Cheers, M.

leommxj commented 8 months ago

Update: CLI works! I found out that I needed to add the address and channel to the command line. So where your example wrote:

python3 mdp.py set voltage 3.3 -d /dev/ttyS16 -I ${MACHINEID}

I needed to write:

python3 mdp.py set voltage 3.3 -d COM5 -a 0xC844267D72 -c 45 -I 0x853707CC

Quite happy to know that the code works with CLI on my P906. I can't get your lib code example to work for some reason. It persists in returning the mdp.RecvError: b''. There is some communication with my unit because the green led flashes, and the led color of the encoder knob changes, but the value does not change.

I think I need the lib code to integrate in my html interface, so it would be great if you could give me some suggestions on how to get it to work. Thanks again Leopold!

Cheers, M.

Hi, Mark. I may not have been clear in the readme file. the address(-a) and channel(-c) arguments have a default value, just for convenient. If you use the following command and pair your p906, it will use the default value (50 as channel and 0x153614fae1 as address). Otherwise, they need to be set.

python3 mdp.py match -d /dev/ttyS16

and you can set the channel/address you want

python3 mdp.py match -d /dev/ttyS16 -c 55 -a 163614fae1

the CLI just simply called lib code, it should be working if CLI is working. the following code should work in your case:

from mdp import P906
from serial import Serial
s = Serial('COM5 ', 115200, 8, 'N', 1, timeout=0.5)
p = P906(s, 0xC844267D72, 45, 0x853707CC)
p.connect()

p.setOutputVolt(3.3)

There is some communication with my unit because the green led flashes, and the led color of the encoder knob changes, but the value does not change.

that is weird, if CLI works normal, it should not be happening.

and one more thing, the communication is not very stable even we place the adapter and p906 close. Sometimes it could fail.

market84 commented 8 months ago

Thanks for your quick reply. I saw the match command indeed, but could not figure it out. The lib code now works as well for me. I still had p.autoMatch() in my code which may have caused the issue.

Indeed I noticed the communication is quite fragile and sometimes I need to retry a few times. CLI is most stable for me, the lib code for some reason is less stable.

One last question: when I use p.getRealtimeValue() in the lib code I do not see any output in the terminal (also no error), while the CLI get command does give output. I may need to put more in the code for this, but my python knowledge is limited. Can you please show me how I can get output from p.getRealtimeValue() in the terminal (I use PlatformIO), or even better, how I can store the p.getRealtimeValue() into a variable?

leommxj commented 8 months ago

@market84

getRealtimeValue should return the voltage and current value in a list if the data obtained successfully, and return None if something goes wrong. (this will happen, comm is not stable :> , just call it again)

>>> from mdp import P906
>>> from serial import Serial
>>> s = Serial('/dev/ttyS16', 115200, 8, 'N', 1, timeout=0.5)
>>> p = P906(s, 0x153614fae1, 50, 0x62e6491b)
>>> p.getRealtimeValue()
[(2, 1), (2, 1), (2, 1), (2, 1), (2, 1), (2, 1), (2, 1), (2, 1), (2, 3)]
market84 commented 8 months ago

In order to get more stable communication I opened the MDP-M01 to see what is inside the display unit. Like the P906 it has an Si24R1, but this one has an extended antenna (see picture). From info online I understood that the Si24R1 is comparable to nrf24l01+, which I use. The antenna inside the M01 is 45 mm and, remarkably, the core is connected to the USB D- line of the micro USB socket that goes with a small USB cable of also 45 mm (see picture) to the P906, which feeds the P906 if used together. I do not know if the P906 does anything with the USB D- connection to the M01, but my assumption is that this is an approach for extending the antenna outside the M01 to a total of 90 mm.

I decided to copy this approach to my nrf24l01+ by adding a 90 mm antenna (see picture), and with good results: I can now move the nrf24l01+ until a distance of around 15 cm from the P906. Unfortunately not a few meters, which is possible with the M01 if you use it wireless with its own USB power. But the 90mm antenna shows an improvement (although still not 100% stable).

One persistent part in my tests is that the getRealtimeValue command still not works for me: it still gives no output, even when I retry many times. This while the CLI get command does give the output and is quite stable now. It may be my code or my PlatformIO setup, but I suspect there could also be something wrong with this command. Could you maybe check this command for its correct working one more time?

I realize this was a very long comment, but I hope it gives useful information to you.

WhatsApp Image 2024-04-02 at 00 59 40_3563bcf5 WhatsApp Image 2024-04-02 at 01 00 48_cac4bb49 WhatsApp Image 2024-04-02 at 01 01 58_6efe964c

leommxj commented 8 months ago

@market84 That is very useful and interesting finding. I didn't even think about miniware trying to boost the signal (partly because the m01's communication range isn't that far either)! Opened my m01 and it's the same structure and it's the same structure in the fcc certification file: internal-photo. Very interesting.

regarding the getRealtimeValue problem, i just check again it works for me, and the get CLI just called it. getRealtimeValue should work if CLI works.

https://github.com/leommxj/mdp_commander/blob/76c40b1139c3e3d46e79f5dcb3c4fdc30d5a3c96/mdp.py#L391-L397

Maybe python environment is different for your code and for CLI? Is other method working in your code? like setOutputCurr . You could try to enable some debug log like this:

from mdp import P906
from serial import Serial
import logging
s = Serial('/dev/ttyS16', 115200, 8, 'N', 1, timeout=0.5)
p = P906(s, 0x153614fae1, 50, 0x62E6491B, log_level=logging.DEBUG)
logging.basicConfig(level="DEBUG")
p.connect()

p.setOutputCurr(3.3)
p.getRealtimeValue()
market84 commented 7 months ago

@leommxj Thanks for checking again! It really helps me to know that getRealtimeValue works for you if CLI works. In that case indeed the cause must be in my python, and I will try some more setups and debugging (and yes, setOutputCurr and all the others are working in my code, issue is only with getRealtimeValue).

I never checked the searchable FCC ID Database before, it provides useful information. Thanks for making me aware of this, I am shure I will use it more in the future for info on my devices.