Sponsored

Kindapointless

Well-Known Member
Joined
Aug 23, 2022
Threads
15
Messages
101
Reaction score
137
Location
Florida
Vehicle(s)
2022 rubicon 2dr
Occupation
Parts guy for mini/bmw
So confirming information like this between 3.5 and 4.0 won't always work btw. 3.5 and 4.0 may have the same info but 4.0 is definitely more locked down about how it responds. Several things that got into specifics of things that 3.5 can tell you are now politely talked around on 4.0 so keep that in mind too, been reported more then once
Sponsored

 
OP
OP
jmccorm

jmccorm

Well-Known Member
First Name
Josh
Joined
Sep 15, 2021
Threads
55
Messages
1,170
Reaction score
1,322
Location
Tulsa, OK
Vehicle(s)
2021 JLUR
Build Thread
Link
Occupation
Systems Engineering
I was thinking of changing the format of the spreadsheet to make the position of the data more clear than $XXXX????00?? and to make it so that it can be read by machine tools such as GPTchat.

Please visit the link, take a look, and let me know.

Jeep Wrangler JL JEEP HACKING CAN-C / CAN-IHS / UDS ! (Reverse Engineering) 1680040221987
 
OP
OP
jmccorm

jmccorm

Well-Known Member
First Name
Josh
Joined
Sep 15, 2021
Threads
55
Messages
1,170
Reaction score
1,322
Location
Tulsa, OK
Vehicle(s)
2021 JLUR
Build Thread
Link
Occupation
Systems Engineering
I've spent the past few hours arguing with ChatGPT because it doesn't know how to convert nibbles into bytes. I guess there's not enough modern books or websites on the subject, so it doesn't know much.

I've gotten it to the point where it analyzes everything correctly... UNLESS you've got three nibbles. No matter what I say, it seems to misunderstand every prompt (every explanation) I've devised so far.
 

Ratbert

Well-Known Member
First Name
John
Joined
Jun 20, 2020
Threads
159
Messages
16,108
Reaction score
25,114
Location
PNW
Vehicle(s)
2022 AEV JL370 JLURD
Build Thread
Link
Occupation
Software Engineer
Clubs
 
I've spent the past few hours arguing with ChatGPT because it doesn't know how to convert nibbles into bytes. I guess there's not enough modern books or websites on the subject, so it doesn't know much.

I've gotten it to the point where it analyzes everything correctly... UNLESS you've got three nibbles. No matter what I say, it seems to misunderstand every prompt (every explanation) I've devised so far.
Wouldn't it be easier to just write that code yourself?
 
OP
OP
jmccorm

jmccorm

Well-Known Member
First Name
Josh
Joined
Sep 15, 2021
Threads
55
Messages
1,170
Reaction score
1,322
Location
Tulsa, OK
Vehicle(s)
2021 JLUR
Build Thread
Link
Occupation
Systems Engineering
Wouldn't it be easier to just write that code yourself?
Yes. I'm trying to create a prompt for you guys. Once someone hands you the right prompt, coding with ChatGPT is effortless.

It's starting to look like the solution may be outside the bounds of what ChatGPT 3.5 can do. It hallucinates solutions. I'll make sure it works cleanly with ChatGPT 4.0 and then see if I can dumb it down for the ChatGPT 3.5 A.I.'s capabilities.
 

Sponsored

Ratbert

Well-Known Member
First Name
John
Joined
Jun 20, 2020
Threads
159
Messages
16,108
Reaction score
25,114
Location
PNW
Vehicle(s)
2022 AEV JL370 JLURD
Build Thread
Link
Occupation
Software Engineer
Clubs
 
Yes. I'm trying to create a prompt for you guys. Once someone hands you the right prompt, coding with ChatGPT is effortless.

It's starting to look like the solution may be outside the bounds of what ChatGPT 3.5 can do. It hallucinates solutions. I'll make sure it works cleanly with ChatGPT 4.0 and then see if I can dumb it down for the ChatGPT 3.5 A.I.'s capabilities.
It's extremely common for it to invoke nonexistent methods. If you tell it that the method doesn't exist it apologizes and rewrites the solution using classes that don't exist. If you tell it about that it again apologies and gives a third solution. Today's fourth solution was basically identical to the first.

It can get pretty frustrating when you think that you're getting close to a real solution.
 
OP
OP
jmccorm

jmccorm

Well-Known Member
First Name
Josh
Joined
Sep 15, 2021
Threads
55
Messages
1,170
Reaction score
1,322
Location
Tulsa, OK
Vehicle(s)
2021 JLUR
Build Thread
Link
Occupation
Systems Engineering
It can get pretty frustrating when you think that you're getting close to a real solution.
I agree! Or when (ChatGPT 3.5 in particular) doesn't know, so it starts hallucinating a response.

In our specific situation, I was able to work around nearly all false solutions by specifying the exact versions of the language and modules, which put an end to most if not all of that nonsense.

Please write Python 3.9.2 scripts that use the Python-CAN module version 4.1.0, the can-isotp module version 1.8, and the can-isotp module 1.8 as needed, but no other versions of those modules.
Giving it some more background information seems to have helped just as well.

The target vehicle is a Jeep Wrangler JL which has two CAN buses: can0 (CAN-IHS) and can1 (CAN-C). Configure for a SocketCAN interface and use a Raspberry Pi environment. The CAN bus has an 11 bit ID.
After that, I'd hit a problem here and there, but as I encountered each problem, I added a clarification to the writing prompt:

Use the set_filters() method for setting a CAN filter and (when a valid option) set timeout=0.001 for can.interface.Bus.recv() calls unless specified otherwise. Do not specify channels or bitrate unless necessary and avoid using the channel_info attribute. Always begin Python3 scripts with #!/usr/bin/python3. Do not include a main guard. If you use isotp.CanStack, you must set tx_data_min_length to 8 and tx_padding to 0x00. The following have been deprecated: ll_data_length, rx_padding, tx_dl, rx_dl.
The problem I'm running into now is that the explanation for how to handle working with a 12-bit variable is equal in size to the prompt above. It simply lacks the skill. I need to find a smarter way of explaining the solution that it understands, rather than telling it step-by-step.

But otherwise, with little or no correction, I'm able to create effective and working code with ChatGPT. The last few scripts (rid, wid, ioid, ecureset) were all written with ChatGPT using writing prompts, and the only time I corrected code by hand was when I thought it'd be easier to do the code change myself rather than explain it, or when the size of the code started to get too big for it to work with.

I think that's the main limitation right now, for me at least. It can only look at so much code at once before it starts forgetting other portions of the code. Kind of like a human, I suppose. It can't keep the whole thing in memory all at once.

That said, it is having problems with effectively using the udsoncan module, so I've put that aside from now. It made the unsolicited remark that the udsoncan documentation is ambiguous, to which I agree, so I don't hold that against it.
 
OP
OP
jmccorm

jmccorm

Well-Known Member
First Name
Josh
Joined
Sep 15, 2021
Threads
55
Messages
1,170
Reaction score
1,322
Location
Tulsa, OK
Vehicle(s)
2021 JLUR
Build Thread
Link
Occupation
Systems Engineering
Here's the latest idea for a new format for the Wranlger CAN bus spreadsheet:




The new format is machine readable, making it something that is easily imported into ChatGPT as a cut-and-paste CSV file.

Here's a selected sample of the new spreadsheet, in CSV format (to cut-and-paste into ChatGPT):

Code:
CAN-C and CAN-IHS Message IDs for the 2018+ Jeep Wrangler JL,,,,,,,,,,,,,,
"MAY ALSO APPLY TO OTHER LATE-MODEL CHRYSLER, DODGE, JEEP, AND FIAT VEHICLES.",,,,,,,,,,,,,,
"Here are ChatGPT's instructions.
Always follow the data table for extracting values from the payload, including the PAYLOAD START NIBBLE and PAYLOAD END NIBBLE values, and double-check the data table for units and conversion factors when processing variables. Check the data table for the encoding format of the variable, including its size (number of bytes) and whether it is signed or unsigned.
In the table that follows, the fields are described as follows:
    CAN IHS: Whether the CAN ID is part of the IHS network or not. Values can be 'Y' (Yes) or 'N' (No).
    CAN C: Whether the CAN ID belongs to the CAN C network. Values can be 'Y' (Yes) or 'N' (No).
    MSG ID: The Message Identifier in hexadecimal format for each CAN message.
    VARIABLE NAME: The name of the variable that is stored in the payload of the CAN message.
    UNITS: In what measurement units VARIABLE NAME is given in. If blank, then the there are no units.
    FORMULA: What formula (if any) to apply to the value before using.
    PAYLOAD START NIBBLE: This field represents the starting offset (in nibbles) that VARIABLE NAME is stored in the payload.
    PAYLOAD END NIBBLE: This field represents the ending offset (in nibbles) that VARIABLE NAME is stored in the payload.
    NEEDS ENGINE RUNNING: Whether the engine needs to be running to receive the message. Values can be 'Y' (Yes) or 'N' (No).
    CAN MESSAGE BYTE LENGTH: The total length of the CAN message in bytes.
    UPDATE RATE: The rate at which the CAN message is updated, typically in seconds or milliseconds.
    ENCODING FORMAT: The format used for encoding the data in the CAN message.
    USAGE NOTES: Additional comments on how the variable should be used.",,,,,,,,,,,,,,
CAN IHS,CAN C,MSG ID,VARIABLE NAME,UNITS,FORMULA TO APPLY BEFORE USING,PAYLOAD START NIBBLE,PAYLOAD END NIBBLE,NEEDS ENGINE RUNNING,CAN MESSAGE BYTE LENGTH,UPDATE RATE,ENCODING FORMAT,USAGE NOTES,,
N,Y,$023,STEERING WHEEL ANGLE,degrees,*2,0,3,Y,8,0.01 seconds,word,"After multiplying by 2, subtract by 0x2000 in order to make 0x0000 become the center value.",,1
N,Y,$023,STEERING WHEEL DRIVER TORQUE,raw value,,4,7,Y,8,0.01 seconds,word,,,1
N,Y,$079,VEHICLE IS STOPPED,raw value,,0,0,N,8,0.02 seconds,array of bits,,,9
N,Y,$079,BRAKE SYSTEM PRESSURE,raw value,,1,3,N,8,0.02 seconds,12-bit word,,,9
N,Y,$079,BRAKE PEDAL PRESSURE,raw value,,5,7,N,8,0.02 seconds,12-bit word,,,9
N,Y,$079,VEHICLE SPEED,MPH,*200,8,11,N,8,0.02 seconds,word,,,9
N,Y,$08B,FRONT DRIVER TIRE SPEED,MPH,*20,0,3,N,8,0.02 seconds,word,,,18
N,Y,$08B,FRONT PASSENGER TIRE SPEED,MPH,*20,4,7,N,8,0.02 seconds,word,,,18
N,Y,$08B,REAR DRIVER TIRE SPEED,MPH,*20,8,11,N,8,0.02 seconds,word,,,18
N,Y,$08B,REAR PASSENGER TIRE SPEED,MPH,*20,12,15,N,8,0.02 seconds,word,,,18
N,Y,$127,INTAKE AIR TEMPERATURE,Celsius,-40,0,1,Y,8,0.10 seconds,signed byte,,,35
N,Y,$127,ENGINE COOLANT TEMPERATURE,Celsius,-40,2,3,Y,8,0.10 seconds,signed byte,,,35
N,Y,$127,BAROMETRIC PRESSURE,absolute kPa,,4,5,Y,8,0.10 seconds,byte,,,35
N,Y,$127,UNKNOWN TEMPERATURE,raw value,,8,9,Y,8,0.10 seconds,byte,,,35
N,Y,$127,UNKNOWN STATUS,raw value,,10,11,Y,8,0.10 seconds,byte,,,35
N,Y,$127,UNKNOWN,raw value,,12,13,Y,8,0.10 seconds,byte,,,35
Basically, there are some embedded instructions in the spreadsheet, and a small selection of rows which describe some of the various parameters we can work with.

Here is the prompt that instructs ChatGPT how to program for the Jeep Wrangler on a Raspberry Pi using the SocketCAN interface:

You will always write to the following standard unless told otherwise:
The target vehicle is a Jeep Wrangler JL with two CAN buses: can0 (CAN-IHS) and can1 (CAN-C). In Python, the CAN data is big-endian. Please write Python 3.9.2 scripts that use the Python-CAN module version 4.1.0, the can-isotp module version 1.8 as needed. Configure for a SocketCAN interface in a Raspberry Pi environment. The CAN bus has an 11 bit ID. Use the set_filters() method for setting a CAN filter and (when a valid option) set timeout=0.001 for can.interface.Bus.recv() calls unless specified otherwise. Avoid using the channel_info attribute and do not specify channels or bitrate unless necessary. Always begin Python3 scripts with #!/usr/bin/python3. Do not include a main guard. If you use isotp.CanStack, you must set tx_data_min_length to 8 and tx_padding to 0x00. The following have been deprecated: ll_data_length, rx_padding, tx_dl, rx_dl. A 12-bit word is 3 nibbles long. Display the code in a Python code box.
Use the following function to extract a variable from a CAN payload but do not include the definition in your code: extract_by_nibble(nibble_start,ending_nibble,payload)
When writing code, you will check all options and parameters for their validity against this standard. Do you understand this directive (YES or NO)?

In the instructions, we reference a function extract_by_nibble(nibble_start,ending_nibble,payload) to pull any variable from a CAN message by specifying it's start and end offset in nibbles:

This function may be of general use to anyone, using artificial intelligence to do their coding or not:

Python:
def extract_by_nibble(nibble_start,ending_nibble,payload):
    if starting_nibble > ending_nibble:
        return 'N/A'
    if ending_nibble >= len(payload) * 2:
        return 'N/A'
    value = 0
    for nibble in range(starting_nibble, ending_nibble+1):
        byte_idx = nibble // 2
        byte = payload[byte_idx]
        shift = (1 - (nibble % 2)) * 4
        nibble_value = (byte >> shift) & 0x0F
        value = (value << 4) | nibble_value
    return value
It handles the extraction of bytes, 12-bit words, and words, even if the starting nibble is not aligned at the byte level. (CompSci geek speak. Sometimes there's some tricky rules when extracting data. This handles it for you.)

Finally, we give it some real instructions:

Create a program which constantly reads from the CAN bus, but once a second prints the current value of STEERING WHEEL ANGLE, VEHICLE SPEED, FRONT DRIVER TIRE SPEED, INTAKE AIR TEMPERATURE.

ChatGPT can be a little funny the way it creates code. It takes a different approach every time you start a new session. If it goes wacky on you, hit the regenerate button and it'll take a new approach if you haven't generated any other code in the current session.

Here is what ChatGPT generated:

Python:
#!/usr/bin/python3

import can
import time

def extract_by_nibble(nibble_start,ending_nibble,payload):
    if starting_nibble > ending_nibble:
        return 'N/A'
    if ending_nibble >= len(payload) * 2:
        return 'N/A'
    value = 0
    for nibble in range(starting_nibble, ending_nibble+1):
        byte_idx = nibble // 2
        byte = payload[byte_idx]
        shift = (1 - (nibble % 2)) * 4
        nibble_value = (byte >> shift) & 0x0F
        value = (value << 4) | nibble_value
    return value

def process_messages(bus, current_values):
    msg = bus.recv(timeout=0.001)
    if msg is not None:
        if msg.arbitration_id == 0x023:
            steering_wheel_angle = extract_by_nibble(0, 3, msg.data) * 2
            steering_wheel_angle = steering_wheel_angle - 0x2000
            current_values["steering_wheel_angle"] = steering_wheel_angle

        elif msg.arbitration_id == 0x079:
            vehicle_speed = extract_by_nibble(8, 11, msg.data) * 200
            current_values["vehicle_speed"] = vehicle_speed

        elif msg.arbitration_id == 0x08B:
            front_driver_tire_speed = extract_by_nibble(0, 3, msg.data) * 20
            current_values["front_driver_tire_speed"] = front_driver_tire_speed

        elif msg.arbitration_id == 0x127:
            intake_air_temperature = extract_by_nibble(0, 1, msg.data) - 40
            current_values["intake_air_temperature"] = intake_air_temperature

def print_values_every_second(current_values):
    print(f"Steering Wheel Angle: {current_values['steering_wheel_angle']} degrees")
    print(f"Vehicle Speed: {current_values['vehicle_speed']} MPH")
    print(f"Front Driver Tire Speed: {current_values['front_driver_tire_speed']} MPH")
    print(f"Intake Air Temperature: {current_values['intake_air_temperature']} Celsius")
    print("\n")

if __name__ == "__main__":
    can_filters = [{"can_id": 0x023, "can_mask": 0x7FF},
                   {"can_id": 0x079, "can_mask": 0x7FF},
                   {"can_id": 0x08B, "can_mask": 0x7FF},
                   {"can_id": 0x127, "can_mask": 0x7FF}]

    bus = can.interface.Bus(channel="can1", bustype="socketcan", can_filters=can_filters)
    current_values = {"steering_wheel_angle": 0,
                      "vehicle_speed": 0,
                      "front_driver_tire_speed": 0,
                      "intake_air_temperature": 0}

    start_time = time.time()

    while True:
        process_messages(bus, current_values)
        elapsed_time = time.time() - start_time
        if elapsed_time >= 1.0:
            print_values_every_second(current_values)
            start_time = time.time()
Fantastic!

It automatically handles vehicle parameters that have been encoded as bytes, 12-bit words, and words. It handles any mathematical transformations that might be necessary before you can use a value (like subtracting -40 before using a temperature). It handles the CAN filters, initializing the CAN bus, reading the values, and printing the values.

That's where I'm at with this. I've got a current system that ChatGPT understands and is able to code Jeep Wranlger JL specific code in Python under a Raspberry Pi running Raspbian and using the SocketCAN interface.
 

NickJar

Well-Known Member
Joined
Jan 18, 2022
Threads
2
Messages
122
Reaction score
88
Location
Toronto
Vehicle(s)
2022 RD
What happens if you send in a zero value for say the throttle position and keep sending it, then press on the gas?
 

oldcjguy

Well-Known Member
First Name
Jim
Joined
Aug 26, 2020
Threads
3
Messages
609
Reaction score
760
Location
Central FL
Vehicle(s)
16 Challenger Hellcat, 19 Challenger Scatpack, 20 JLUR Recon
Occupation
Software Engineer
What happens if you send in a zero value for say the throttle position and keep sending it, then press on the gas?
For safety it would probably go into limp mode and disable the throttle as the ecu would be receiving contradicting messages between your messages and the throttle's actual messages.
 

Sponsored

NickJar

Well-Known Member
Joined
Jan 18, 2022
Threads
2
Messages
122
Reaction score
88
Location
Toronto
Vehicle(s)
2022 RD
For safety it would probably go into limp mode and disable the throttle as the ecu would be receiving contradicting messages between your messages and the throttle's actual messages.

Interesting, my jeep got stolen a little while ago. I'm trying to figure out if I want to get another one (which I do). The problem is, I hear is they will be back for your new one. I'm wondering if I do something where I flood canbus while its locked with a throttle position of 0, if that would help stop them from stealing it. Or something along those lines
 

gus2k

Active Member
First Name
Gus
Joined
Aug 3, 2021
Threads
4
Messages
31
Reaction score
41
Location
CA
Vehicle(s)
2021 JLUR
Hey @jmccorm! Been lurking on this thread and seeing your work, narrative, and inventive use of ChatGPT :)

I'd love to chip in, but might need a pointer or two getting started. I've now got a WiCAN attached to the driver-side OBD2 port, and I've managed to get SavvyCAN to talk to it over TCP. But.. that's where usefulness is going cold. I see a handful of 0x7FF frames but not much else. Am guessing I need to start talking to the device somehow.

What would be a good tool/script to throw at it to see some.. more interesting infromation? My short term goal is to understand an active CEL, haha. My longer term goal is to build some smart garage stuff.

I'm pretty handy with esphome, python, programming and protocols generally - but a noob to all these automotive protocols. Apologies if asking for a pointer is slightly off topic, cheers!
 

Drdyer9051

Active Member
First Name
Bradley
Joined
Feb 1, 2022
Threads
0
Messages
33
Reaction score
24
Location
East Tennessee
Vehicle(s)
4BT-Tj,Tj,4B-Comanche,2021JLUR,diesel 22JTR
BCM $A01A - OIL CHANGE STATISTICS

Here's another discovery that I wish I could claim credit for. You can determine how many engine revolutions, how many hours, and how many kilometers it's been since your last oil change. (Or since you've done an "oil change reset" on your dash.)

Ready?

# rid -d bcm A01A # Remember, -d is DECIMAL output
13 152 0 38 2 245

ENGINE REVOLUTIONS SINCE OIL CHANGE:
We take the first two numbers (in big-endian format) and multiply it by 1000. So...​
((13*256)+152)*1000 = 3,480,000 engine revs

HOURS SINCE OIL CHANGE:
We take the next two numbers (in big-endian format) to calculate the number of hours.​
(0*256)+38 = 38 hours
KILOMETERS SINCE OIL CHANGE:
We take the final two numbers (in big-endian format) to calculate the number of kilometers.​
(2*256)+245 = 757 kilometers (470 miles)

Enjoy!

And one very special thank-you to our benevolent anonymous patron for sharing this with us!


I was able to use your RID program (python3 rid.py -d bcm A01A) to get
51 5 0 163 26 209
so 13,061,000 revs
163 hours since oil change
6865 Km or 4265 miles since change

thanks,

so when I try to get Cabin Temperature from hvac at D01E

python3 rid.py -d hvac D01E

I get No response received within 2 seconds.

other modules work like tcm 1018 for Crankshaft Actual Torque it
returns 7 240

anyone able to get temperatures from the hvac module?


edit: I am looking into the problem of heater blowing super hot when controls are set to say 73 and it is below 40 degrees outside. I have to put it to low, let it blow cool air and then raise to 73...
this is a known problem and I would like to try to get a work around.


Second Edit: found problem.... hardware problem on can0
 
OP
OP
jmccorm

jmccorm

Well-Known Member
First Name
Josh
Joined
Sep 15, 2021
Threads
55
Messages
1,170
Reaction score
1,322
Location
Tulsa, OK
Vehicle(s)
2021 JLUR
Build Thread
Link
Occupation
Systems Engineering
edit: I am looking into the problem of heater blowing super hot when controls are set to say 73 and it is below 40 degrees outside. I have to put it to low, let it blow cool air and then raise to 73...
I know that Jeep had a problem with the HVAC that they fixed with a firmware update. The firmware update was already applied to my 2021 June Wrangler, what month is your Wrangler?
 

Drdyer9051

Active Member
First Name
Bradley
Joined
Feb 1, 2022
Threads
0
Messages
33
Reaction score
24
Location
East Tennessee
Vehicle(s)
4BT-Tj,Tj,4B-Comanche,2021JLUR,diesel 22JTR
I know that Jeep had a problem with the HVAC that they fixed with a firmware update. The firmware update was already applied to my 2021 June Wrangler, what month is your Wrangler?

2022 Diesel Gladiator
Sponsored

 
 







Top