Kid communication data

Started by caribou, June 16, 2015, 12:41:10 AM

Previous topic - Next topic

caribou

I wrote a little python script that read data from KID via serial port. 

The kid is connected to a raspberry pi using a serial to usb adapter.

For now, it retrieve data on serial port that the KID.

Following the instructions that Mario give on the other post, the data was parse to determine the type of packet then parse the register name and print register data.

I was able to print these information that the kid send every 12 seconds

witch(master_var_send){   
      handle_set_send(COMM_batteryTemp, dispavg_batt_temp);
      handle_set_send(COMM_batteryStage, BattChargeStage);     
      handle_set_send(COMM_absorbV, absorbV);     
      handle_set_send(COMM_floatV, floatV);   
      handle_set_send(COMM_eqV, eqV);     
      handle_set_send(COMM_TempCompV, BattTempCompOrigValue);   
      handle_set_send(Comm_BattNominal, battery_nominal);     
      handle_set_send(COMM_vBATT, dispavgVbatt);   
      handle_set_send(COMM_absorbT, absorbT);     
      handle_set_send(Comm_EqT, eqT);


I was able to display correctly variable that contain voltage, time and battery stage but for temperature, I only print the value.  More information is needed for conversion

I try to retrieve vPV but without success...  I'll try again!

Mario, is it possible to get more detail on how the XOR work for the fourth byte?


Jean-Francois

Mario

Hi caribou,
The XOR, has to be done every 2 bits of every byte and at the end XOR with itself and you should get 0 to be success.

the value you are getting is in Integer form so you will need to create a function that converts it from Int to ASCII to be able to make sense of the data, thats pretty common to do.

Mario

dgd

#2
Quote from: Mario on June 23, 2015, 04:07:55 PM
The XOR, has to be done every 2 bits of every byte and at the end XOR with itself and you should get 0 to be success.

Ok, sort of, how about a little example of how this actually works. Thanks

..and
Is there a command to force the KID into a particular charge state, maybe its there but I just can't see it.
I'm trying to implement a follow-me scheme so that the KID can follow a Classic (or another KID etc) into Absorb and Float etc. - via web server  :)

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

caribou

An another update...

I create 2 scripts, KidServer and KidViewer

KidServer communicate with Kid and start server socket.
KidViewer connect to KidServer via port 50008 and display data that KidServer send.

KidServer can be executed alone.  It will start 2 threads.  The first one will read serial data packet from Kid, check data integrety with xor operation.  After, packet are dissemble to fill the structure KidData

class KidData:
    def __init__(self):
        self.comm_battery_temp=0.0
        self.comm_battery_stage=0
        self.comm_absorb_v=0.0
        self.comm_float_v=0.0
        self.comm_eq_v=0.0
        self.comm_temp_comp_v=0.0
        self.comm_batt_nominal=0.0
        self.comm_v_batt=0.0
        self.comm_absorb_t=0.0
        self.comm_eq_t=0.0
        self.comm_v_pv=0.0
        self.comm_kwh=0.0
        self.comm_fet_temp=0.0

The second thread, handle tcp connection via socket port 50008. 
When connection is established, KidServer wait for GET, ask Kid for data and reply with sending the KidData structure.

KidViewer connect to KidServer and display data.  It use tkinter for displaying data.

To run KidServer, put in the same directory KidServer.py, kid_data.py and type this command : python KidServer.py

To run KidViewer, put in the same directory KidViewer.py, kid_data.py and type this command : python KidViewer.py

Don't forget to change the host ip address into the KidViewer script.

Sorry for my python syntax.. I'm learning in the same time I write those script.  :)


Mario,

I was able to write to Kid but when I try to get KWH (COMM_KWH =13), I get nothing...

For the temperature value, I read Integer but, I don't know what operation should I do to extract the temperature... 
For example, when I got the value 500 that correspond aproximatly to 25 deg. C. Howto handle the negative value?

Could you give the other register enum for SOC, Remaining Amp Hours, PV current?

I'll be happy to get some feedback!

Thanks!  ;D

felix

Hi can someone please show me how to wire this up to the PI?

esol

Hello Caribou,

I've been following this post and the other one where Mario has explained what the enumeration values that correspond to the variables and I am trying to understand how your python script works.  I am using an rj11 cable connected to the master port on the kid which is then connected to a rj11 to rs232 adapter that is then connected to an rs232 to USB adapter which I then connect to my ubuntu machine.  I use the terminal to run your Python script. 

I was able to run KidSerial.py and it spits out data on the terminal.  I then run KidViewer.py and it is unable to make a connection to a socket and it times out.  After it times out, there is a dialog box named Tk that displays a gui with various input values that I can change but they all display 0.  Both server and viewer are in the same directory as kid_data.py.  Is that ok or should they both be in separate directories?
I would appreciate some help on this. 

Also, I am reading through your code and I am not sure what the Xor portion of the 4 bit packet is used for? I understand that the first 2 bytes are PK Type, the next 6 are what enumerated variable to set, the next 16 are the actual data value and the last one is Xor.  Can you explain what the Xor packet is used for?  I am trying to understand what is going on in your script.  Thank you Caribou.  Kudos on what you have done so far  :)