Skip to content

Commit

Permalink
Get firmware version via tedapi #97
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Jul 6, 2024
1 parent 0d6bd32 commit f324eff
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,4 @@ proxy/teslapy
j
config.json
status.json
tools/tedapi/firmware.raw
24 changes: 24 additions & 0 deletions tools/tedapi/ComponentsQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@
battery_type = battery['type']
print(f" - Battery Block: {vin} ({battery_type})")

# Fetch Firmware from Powerwall
print(f" - Fetching /tedapi/v1 PW3 Firmware from Powerwall ({din})...")
# Build Protobuf to fetch firmware
pb = tedapi_pb2.Message()
pb.message.deliveryChannel = 1
pb.message.sender.local = 1
pb.message.recipient.din = din # DIN of Powerwall
pb.message.firmware.request = ""
pb.tail.value = 1
url = f'https://{GW_IP}/tedapi/v1'
r = requests.post(url, auth=('Tesla_Energy_Device', gw_pwd), verify=False,
headers={'Content-type': 'application/octet-string'},
data=pb.SerializeToString(), timeout=5)
print(f"Response Code: {r.status_code}")
# write raw response to file
with open("firmware.raw", "wb") as f:
f.write(r.content)
print(" - Firmware Written to firmware.raw")
# Decode response
tedapi = tedapi_pb2.Message()
tedapi.ParseFromString(r.content)
firmware_version = tedapi.message.firmware.system.version.text
print(f"Firmware version (len={len(firmware_version)}): {firmware_version}")

# Fetch ComponentsQuery from Powerwall
print(f" - Fetching /tedapi/v1 PW3 ComponentsQuery from Powerwall ({din})...")
# Build Protobuf to fetch config
Expand Down
126 changes: 126 additions & 0 deletions tools/tedapi/tedapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message MessageEnvelope {
int32 deliveryChannel = 1;
Participant sender = 2;
Participant recipient = 3;
FirmwareType firmware = 4;
optional ConfigType config = 15;
optional QueryType payload = 16;
}
Expand All @@ -39,6 +40,51 @@ message Tail {
int32 value = 1;
}

// ***** Query = 4 ****

message FirmwareType {
oneof id {
string request = 2;
FirmwarePayload system = 3;
}
}

message FirmwarePayload {
FirmwareDIN part = 1;
string din = 2;
FirmwareVersion version = 3;
FirmwareFive five = 5;
int32 six = 6;
DeviceArray wireless = 7;
bytes field8 = 8;
bytes field9 = 9;
}

message FirmwareDIN {
string number = 1;
string serial = 2;
}

message FirmwareVersion {
string text = 1;
bytes code = 2;
}

message FirmwareFive {
int32 d = 2;
}

message DeviceArray {
repeated DeviceInfo device = 1;
}

message DeviceInfo {
StringValue company = 1;
StringValue chip = 2;
StringValue data1 = 3;
StringValue data2 = 4;
}

// ***** Query = 16 *****

message QueryType { // 16
Expand Down Expand Up @@ -179,4 +225,84 @@ message StringValue {
// }
// 2 {
// 1: 1
// }
//
// REQUEST - firmware
// 1 {
// 1: 1
// 2 {
// 3: 1
// }
// 3 {
// 1: "1707000-00-J--TG9999999999XP"
// }
// 4 {
// 2: ""
// }
// }
// 2 {
// 1: 1
// }

// RESPONSE - firmware
// 1 {
// 1: 1
// 2 {
// 1: "1707000-00-J--TG9999999999XP"
// }
// 3 {
// 3: 1
// }
// 4 {
// 3 {
// 1 {
// 1: "1707000-00-J"
// 2: "TG9999999999XP"
// }
// 2: "1707000-00-J--TG9999999999XP"
// 3 {
// 1: "24.12.6-PW3-AFCI 008bf6ff" <--- PW3 firmware version
// 2: "\000\213\366\...Redacted..."
// }
// 5 {
// 2: 1
// }
// 6: 4
// 7 {
// 1 {
// 1 {
// 1: "Quectel"
// }
// 2 {
// 1: "BG95-M2"
// }
// 3 {
// 1: "XMR2020BG95M2"
// }
// 4 {
// 1: "10224A-2020BG95M2"
// }
// }
// 1 {
// 1 {
// 1: "Texas Instruments"
// }
// 2 {
// 1: "WL18MODGI"
// }
// 3 {
// 1: "Z64-WL18DBMOD"
// }
// 4 {
// 1: "451I-WL18DBMOD"
// }
// }
// }
// 8: "\370!s\306\212...Redacted..."
// 9: "\373U\353\322...Redacted..."
// }
// }
// }
// 2 {
// 1: 1
// }
58 changes: 36 additions & 22 deletions tools/tedapi/tedapi_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f324eff

Please sign in to comment.