Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Tesla Wall Connector load sharing protocol

This site may earn commission on affiliate links.
All was working fine for weeks but recently I got a problem, not really related to the script but more to the serial-to-usb driver it seems:

Code:
[18830.252081] usb 1-1: USB disconnect, device number 3
[18830.252457] ftdi_sio ttyUSB1: error from flowcontrol urb
[18830.252930] ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1
[18830.253007] ftdi_sio 1-1:1.0: device disconnected
[18830.451813] Indeed it is in host mode hprt0 = 00021501
[18830.651727] usb 1-1: new full-speed USB device number 4 using dwc_otg
[18830.651963] Indeed it is in host mode hprt0 = 00021501
[18830.887408] usb 1-1: New USB device found, idVendor=0403, idProduct=6001
[18830.887426] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[18830.887433] usb 1-1: Product: USB-RS485 Cable
[18830.887440] usb 1-1: Manufacturer: FTDI
[18830.887446] usb 1-1: SerialNumber: FT2FZ7WG
[18830.909034] ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected
[18830.909237] usb 1-1: Detected FT232RL
[18830.909847] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

Of course the script crashes after this. Is it a faulty hardware or a cable broken or what am I suppost to do now?
 
Thanks for sharing the video! Could TWCManager be used to broadcast its own WiFi network? For instance, can I use it to to prevent other people from using my wall connector in an apartment complex garage (that doesn't have wifi signal)?

It would be cool if I can manually shutoff and turn on the wall connector from my phone.
 
Update here for Powerwall users with a couple of bug fixes and damping of the green energy amps. When monitoring mine it was suffering from slight delays with the powerwall charging so it was switching between 9A and 6A every 10 seconds. This is fixed by altering the green amps offered by a max of 1A each 10s.

I've also attached a screenshot of the powerwall screen showing how the charging tracked the solar once my powerwall got up to the target 70% charge. As the sun dipped, the charging stopped as the green energy dropped and the powerwall picks up the excess for the rest of the day.
 

Attachments

  • TWCManager-with-Powerwall.zip
    47.9 KB · Views: 101
  • twcmanager-powerwall.jpg
    twcmanager-powerwall.jpg
    82.1 KB · Views: 182
I've finished decoding the 11 new commands in the new firmware. Although two of them are clearly intended to stop/start charge, they mostly just flip the main relays and fail to send a CAN message to the car telling it to start or stop. When the TWC stops charging, the ring around the car plug continues flashing green for ~30 seconds, goes blue for a couple seconds (presumably asking the TWC to resume charging), green for a bit longer, then red. After that, start charge command will not start charging again until you re-plug the car.

Basically, it looks like Tesla failed to test that stop/start charge actually works with a Tesla vehicle. WTF?? I can't really imagine how or why they could make such an error, especially since they had it working in firmware from 2016. My only possible theory is that maybe it somehow works with the newest Tesla vehicles but not with my 2014 car? Or they threw it in with no real testing because it's not used during normal operation? Or maybe it's like an emergency stop where they don't care if the car can be started again, but then why include a start command?

I put the TWC in legacy communication mode (DIP switch 2 off) and then I can successfully stop and start charge via the commands, but it's no more effective than ceasing communication with the TWC until the car stops charging. After some random number of stops, the car will refuse to start again until it's re-plugged. I also found the stop/start tests caused the car UI to change to a 30A limit instead of 40A at some point and it did not return to 40A upon re-plugging.

I ran tests using a 2017 TWC and a March 2018 TWC that the new firmware came with - both behaved the same. I also tried other things like setting the charge rate to 0A before stop charge and using the FCE7 command to reset the CAN network before stopping or before starting charge. Nothing made a difference.

None of the other new commands has anything to do with stop/start charging. The other nine commands will:
1) Enter a test state where all LEDs turn green and an orange LED in the middle stays on. Car will actually charge in this state, in which case the LEDs stream green but orange LED in middle remains lit.
2) Exit test state.
3) Return four bytes at memory location 8CF0 and 8CF1. These bytes are always zero in any state I could think to test.
4) Get state of the plug. Returns 0 when unplugged, 1 when charging, 3 when plugged in but not charging (for any reason, including error). It can also return 2 but I could not find a state where 2 was returned. Works with fake car in legacy communication mode as well.
5) Get firmware version including build number. Returns 4.5.3.2 with March 2018 TWC. Also returns TWCID of the unit. The old firmware version command returns only 4.5.3 and does not include TWCID.
6) Return (S)TSN plus the TWCID of the unit.
7) Return first 7 characters of VIN number of connected car. If DIP 2 is off (legacy communication mode) or fake car is plugged in, returns all zeros.
8) Return next 7 characters of VIN.
9) Return last characters of VIN.

So the new firmware still doesn't solve the stop/start charge problem or give us battery state. *sigh* But I can update TWCManager to display whether a car is plugged in or not, and to use the VIN number of the plugged car to stop/start the correct car using car API commands.




Nothing in the firmware checks if GPIO 34 is high or low, so it probably connects to a peripheral that does something when it's high or low. There is only one function in the latest firmware that does anything with GPIO 34: It sets GPIO 34 low as well as setting many other GPIO pins high or low, accesses a number of memory addresses of unknown function, and does something different depending on whether Serial Peripheral Interface A (SPI A) Status Register bit 0x20 is set or not.

What is your firmware version? You can find out using http://<raspberry pi address>/index.php?sendTWCMsg=FB1B&submit=1

If it returns 4.5.3, please get me the extended firmware version using: http://<raspberry pi address>/index.php?sendTWCMsg=FBEC7777<TWCID of slave>&submit=1
Thanks for all your work!

Can we know what these magical new VIN commands are for the newest firmware?
 
Thanks for all your work!

Can we know what these magical new VIN commands are for the newest firmware?
Probably to track car capabilities (older cars may not support everything). This also opens up a possibility for access control list for HWPC (allowing or disallowing cars on any particular HPWC, say you have one installed in a shared apartment complex parking - prevent people stealing your electricity while you're not there).
 
Hi all,

Wow, as soon as I stop paying attention, suddenly there's a ton of interest in this project!

I've gotten really busy lately and have been hired to code stuff for chargers professionally so my time has become really limited, but let me try to answer all the questions from the last couple months...

First, I'm still interested in knowing when/if Tesla releases new firmware versions, so if anyone has a newly purchased TWC, please continue to send me its firmware version and date of manufacture as follows:
  • Visit this URL: http://<raspberry pi address>/index.php?sendTWCMsg=FB1B&submit=1
  • If it returns 4.5.3 or later:
    • Please get me the date of manufacture by visiting:
    • http://<raspberry pi address>/index.php?sendTWCMsg=FB19&submit=1
    • and the extended firmware version by visiting:
    • http://<raspberry pi address>/index.php?sendTWCMsg=FBEC7777<TWCID of slave>&submit=1
    • where <TWCID of slave> must be replaced by your TWC's 4-digit ID which is shown in the web UI.
    • Send me results by clicking my name at the top of this post, then click 'Start a conversation', or post here if you prefer.
I've my EU wallconnector running in 16A master mode. Is there a way to get information out of it like firmware version or VIN of the connected car while running TWCManager in slave mode?

I think Master mode will respond to most messages like firmware version and VIN but I haven't tested.

Would be cool if the TWCManager could be purchased as a completed device

I considered offering this but there are too many legal issues of liability in the US for me to feel it's worth the risk. You could probably ask a local electronics repair place to put the parts together for you though.

I'm running Firmware version: 4.4.13
Should I upgrade it, or can I even upgrade it?

It would be great to upgrade the firmware, but unfortunately it requires a piece of hardware that costs about $30, plus a specialized cable that is a bit tricky to solder together. Or you can probably buy a specialized adapter but I didn't bother spending much time trying to source one. And then you need to install and figure out the software that reads/writes the firmware. Overall, it's not something an average home user would be able to do.

Hopefully someday Tesla will get their TWC firmware update through the car system working and then everyone will have the latest firmware.

@CDragon
1./ @sparkypete has made a great Tesla Powerwall integration, i wonder if this could be merged into main code branch.

Something like powerwall integration should be added using a "Branch" in the git repository. When I change anything in the main repository it's generally easy to merge in those changes to the branch. Putting support for every type of green energy system in the main repository would make it too complicated unless we come up with a system to have each type of system in its own file and users can pick which file gets loaded, but I don't feel I have time to try to orchestrate that.

If someone wants to start a branch, you will need to create an account at github.com. If you can't figure out how to branch the TWCManager repository, click my name at the top of this post, then click 'Start a conversation' and ask me how.

Can we know what these magical new VIN commands are for the newest firmware?

Potentially useful commands in firmware 4.5.3 are:
  • Remember, these commands won't work in TWCs containing firmware with a lower number than 4.5.3. 4.5.3 was included in TWCs manufactured around March 2018 and later.
  • FC B1 SS SS RR RR
    • Tell TWCID RR RR to start charging. SS SS is the fake master TWCID.
  • FC B2 SS SS RR RR
    • Tell TWCID RR RR to stop charging. SS SS is the fake master TWCID.
    • Stop charge command is seriously bugged in that it will cause a plugged-in Tesla to show a red ring around its charge port as soon as you send the command. Car will refuse to charge again until you send start charge command and then physically re-plug the car.
    • If you set DIP switch 2 in the TWC to the down position, it turns off CAN communication to the car and start/stop charge actually work correctly except if you stop and start charging more than once, the car will randomly decide the charger is bad and refuse to charge again until you re-plug the car. The car may also decide to limit itself to 30A charging and that change is permanent unless you raise amps using the car UI.
    • Basically I'm saying stop/start charge commands are useless for most purposes as they are implemented in firmware 4.5.3.
    • The reason cars respond badly seems to be that stop/start simply turn the relays in the TWC off or on but do not send any CAN message to the car telling it to stop or start (I reached those conclusions by looking at the firmware). My 2014 Model S responds to this by trying to use CAN to start the charger again (car ring flickers blue to show CAN communication) and after a bit it enters perma-error state unless DIP 2 is down which disables all CAN communication. Conceivably, Model 3 or X don't respond badly which is how this escaped quality control? If anyone has a 3 or X or a newer S, please test and let me know.
  • FB B4
    • Get plug state. All TWCs on network return FD B4 RR RR XX where RR RR is the TWCID reporting its plug state and XX is 00 when TWC is unplugged, 01 when charging, 03 when plugged in but not charging for any reason (including error). Rarely, 02 is returned but I've seen no pattern to why - I suspect it means the TWC is booting or currently updating the plug state.
  • FB EE SS SS RR RR
    • Tell TWCID RR RR to return first 7 characters of VIN of connected car. SS SS is the fake master TWCID. Response message is FD EE RR RR VV VV VV VV VV VV VV where VV is an ascii character code representing a letter or number. VV will be all zero when car CAN communication is disabled (DIP switch 2 down) or when a non-Tesla vehicle is plugged in using something like a JDapter.
  • FB EF SS SS RR RR
    • Tell TWCID RR RR to return the middle 7 characters of VIN of connected car.
  • FB F1 SS SS RR RR
    • Tell TWCID RR RR to return the last 7 characters of VIN of connected car. US cars only have 3 characters to return with this message but maybe some in other countries have more?
@CDragon
Not sure whether you saw this or not, but Tesla has released the HPWC control spec, at least to Maxem (according to this article). Have you tried reaching out to Tesla to see if you can get a copy too?

People I know have reached out and they only share that info with large corporate users like Maxem. However, thanks to firmware decoding, I'm 99% sure I know all the commands in the latest TWC RS485 control set (1% unsureness comes from the extraordinarily unlikely possibility that they hid additional commands using some form of obfuscation).
 
Last edited:
  • Informative
Reactions: laalves911
In my last post I said people wanting to create versions to support things like Tesla Powerwall should create a Branch. I should have said they should create a Fork. To do so:
  • Log in or create an account at github.
  • Visit the TWCManager github repository.
  • Click the word "Fork" in the upper right:
    upload_2018-12-3_10-48-17.png
  • After a minute or two you'll arrive on a page like this:
  • upload_2018-12-3_15-42-41.png

  • Click the green Clone or download link button (circled in red) to get a link to download the forked code to your raspberry pi using this git command:
    • git clone -b master --single-branch <link revealed by green button> ~/MyTWCFork
  • Copy code from ~/TWC to ~/MyTWCFork, or maybe swap their names to keep developing in ~/TWC.
  • If you made changes to the html code, you'll also have to run cp / var / www / html / * ~/MyTWCFork/HTML
  • Use git commit, then git push to push changes from your local files to your code on github, then give out your github link for people that want to use your fork.
 
  • Informative
Reactions: laalves911
I think Master mode will respond to most messages like firmware version and VIN but I haven't tested.
Thanks for this tip, its working in Master mode (TWCManager is running with fakeMaster=2).
Code:
Response: FD 1B 04 03 0D 00 00 00 00 00 00 00 00 2F
Decoded response
Firmware version: 4.3.13

Response: FD 19 41 31 36 4B 30 30 xx xx xx xx xx 75
Decoded response
(S)TSN: A16K00xxxxx (manufactured between May 20th and Jun 2nd 2016, TWCID 9861)

Response: FD 1A 45 56 57 32 54 33 32 48 4C FF 00 8A
Decoded response
Model: EVW2T32HL
I've rented a Model X over the weekend and since my current version is rather old I hope it will upgrade to 4.5.3 so I can fetch the cars VIN.
 
Hey all,

This is a great project and I have an idea to adapt it to my current situation. My Tesla Wall Connector is fed by a DCC-9-30, which is necessary due to the low rating of my main circuit breaker. Its purpose is to cut off the wall connector once overall current reaches 80% of the rating of the main breaker (56A out of 70A in my case). What I'd like to create is a design that instructs the wall connector to actively dial back the current as the total household approaches the limit. This way my car can continue to charge at a slower rate as opposed to being cut off altogether.

I know my way around embedded Linux systems pretty well but I'm thinking this application may be better suited for a flash-based microcontroller (ie Atmel SAM, Freescale/NXP Kinetis, STM32, etc) since there are existing resources for implementing energy monitors with them. Has anyone made any effort to port this project - or maybe a portion of it - from Python to C?
 
've rented a Model X over the weekend and since my current version is rather old I hope it will upgrade to 4.5.3 so I can fetch the cars VIN.

Unfortunately Tesla has not enabled updating TWCs through cars at this point. There was some evidence that they tried to enable it and it ended up stalling during update, which they probably fear could brick TWCs or at the very least create calls to support asking about error messages. I'm working with a few TWCs at this point that get plugged into many cars each day (including model 3s) and they remain stuck on older firmware.
 
Hi All, I’ve been following this thread for a while and have read all through it but haven’t seen anyone doing what I’d like to do, I’d like to use this but read the grid feed from my SMA Sunny Home Manager 2.0, I’m currently pulling the values from that device and storing them in an influxDB and graphing them using Grafana, is there an easy way to do this? Thanks to all that have put the time and effort into the system already and offering it for use
 
All was working fine for weeks but recently I got a problem, not really related to the script but more to the serial-to-usb driver it seems:

Code:
[18830.252081] usb 1-1: USB disconnect, device number 3
[18830.252457] ftdi_sio ttyUSB1: error from flowcontrol urb
[18830.252930] ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1
[18830.253007] ftdi_sio 1-1:1.0: device disconnected
[18830.451813] Indeed it is in host mode hprt0 = 00021501
[18830.651727] usb 1-1: new full-speed USB device number 4 using dwc_otg
[18830.651963] Indeed it is in host mode hprt0 = 00021501
[18830.887408] usb 1-1: New USB device found, idVendor=0403, idProduct=6001
[18830.887426] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[18830.887433] usb 1-1: Product: USB-RS485 Cable
[18830.887440] usb 1-1: Manufacturer: FTDI
[18830.887446] usb 1-1: SerialNumber: FT2FZ7WG
[18830.909034] ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected
[18830.909237] usb 1-1: Detected FT232RL
[18830.909847] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

Of course the script crashes after this. Is it a faulty hardware or a cable broken or what am I suppost to do now?

I just noticed this question. The last line, "FTDI USB Serial Device converter now attached to ttyUSB0" sounds like it's working to me. What exact error are you seeing? If you're still convinced it's the USB device, try ordering another one. I did find a slightly cheaper ($25) version of the official FTDI RS485 chip board here.
 
@CDragon thanks for getting back to me.

I have changed some lines in your code to take an alternative USB device once the original failed. That worked very well as a workaround so far. No more problems even though I don't think my way is a good one to handle it.

I will probably get another device next year (once I can get some decent Amps from my PV again).

I will also publish my changes on github for everyone having same issues and/or a SolarEdge Inverter to get the required data for green-energy-tracking.
 
  • Like
Reactions: UlrA