Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlocking charge plug by wire #1

Open
alx2k opened this issue Jun 24, 2020 · 7 comments
Open

Unlocking charge plug by wire #1

alx2k opened this issue Jun 24, 2020 · 7 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@alx2k
Copy link

alx2k commented Jun 24, 2020

If you allow me, I modified your code so it can also remove the charging cable when connected.

It consists in a ESP32 (I used a compatible wemos esp32 d1 mini, a lipo battery, a wemos relay shield, and a STX882) PP cable is connected on the NC side of the relay, and it only cuts if the esp32 is powered on, and a registered BLE device is closeby.

Thank you for your code.

Regards,

CODE:
`/*

  • TeslaChargeDoorOpener
  • This sketch will send a signal that will open the charge port door of a Tesla car.
  • It is similar to the button of a Tesla charge cable when not plugged into the car.
  • It will send the signal when powered on, then do nothing. Suited for battery-powered
  • operation using a push button.
  • Pin 11 must be connected to the signal pin of an ASK STX882 433.92MHz transmitter
  • that can be bought on eBay for a low price.
  • The message has been grabbed by using an SRX882 receiver to pick up the data sent
  • by a Tesla charging cable with built in push button.
  • The cable uses this signal to open the charge door when pushing the button not being plugged in.
  • When plugged in, the button on the cable can unlock the cable too. This is not done by RF, so
  • this sketch will not unlock the cable when plugged in.
  • The signal will be sent 5 times repeatedly, just like the charge cable button does.
  • Author: Fred Larsen
  • Github: www.github.com/fredilarsen
  • License: Apache
    */

// Libraries
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEAddress.h>
#include <BLEAdvertisedDevice.h>

// Authorized BLE devices

String mybluetoothdevice1 = "11:22:33:44:55:66";
String mybluetoothdevice2 = "11:22:33:44:55:66";
String mybluetoothdevice3 = "11:22:33:44:55:66";
String mybluetoothdevice4 = "11:22:33:44:55:66";

// Pins
const uint8_t signalPin = 17; // The number of the pin with the output signal
#define LED_BUILTIN 22
// The signal to send
const uint16_t pulseWidth = 400; // Microseconds
const uint16_t messageDistance = 23; // Millis
const uint8_t transmissions = 5; // Number of repeated transmissions
const uint8_t messageLength = 43;
const uint8_t sequence[messageLength] = {
0x02,0xAA,0xAA,0xAA, // Preamble of 26 bits by repeating 1010
0x2B, // Sync byte
0x2C,0xCB,0x33,0x33,0x2D,0x34,0xB5,0x2B,0x4D,0x32,0xAD,0x2C,0x56,0x59,0x96,0x66,
0x66,0x5A,0x69,0x6A,0x56,0x9A,0x65,0x5A,0x58,0xAC,0xB3,0x2C,0xCC,0xCC,0xB4,0xD2,
0xD4,0xAD,0x34,0xCA,0xB4,0xA0};

int scanTime = 20; //In seconds
BLEScan* pBLEScan;
BLEScan* pServerAddress;

void sendSignals() {
Serial.println("sending chargeport transmission, disabling PP");
digitalWrite(LED_BUILTIN, HIGH); // Turn relay high, so it CUTS PP pin in order to unlock handle.
for (uint8_t t=0; t<transmissions; t++) {
for (uint8_t i=0; i<messageLength; i++) sendByte(sequence[i]);
digitalWrite(signalPin, LOW);
delay(messageDistance);
}
Serial.println("transmission ended, giving time for charging handle removal");
delay(10000); // Let's give you 10 seconds to remove the handle.
Serial.println("activamos manguera");
digitalWrite(LED_BUILTIN, LOW); // Turn relay low, reconnecting PP pin in order to lock handle.
}

void sendByte(uint8_t dataByte) {
for (int8_t bit=7; bit>=0; bit--) { // MSB
digitalWrite(signalPin, (dataByte & (1 << bit)) != 0 ? HIGH : LOW);
delayMicroseconds(pulseWidth);
}
}

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
// Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
// Serial.print("BLE Advertised Device found: ");
// Serial.println(advertisedDevice.toString().c_str());
// Serial.println(advertisedDevice.getAddress().toString().c_str());
String resultaddress = advertisedDevice.getAddress().toString().c_str();
if (resultaddress == mybluetoothdevice1 || resultaddress == mybluetoothdevice2 || resultaddress == mybluetoothdevice3 || resultaddress == mybluetoothdevice4) {
Serial.println("BLE device found");
pBLEScan->stop();
sendSignals();
// delay(10000);
}
}
};

void setup() {

pinMode(LED_BUILTIN, OUTPUT);
pinMode(signalPin, OUTPUT);
digitalWrite(signalPin, LOW);

Serial.begin(115200);
Serial.println("Scanning...");

BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(40);
pBLEScan->setWindow(39); // less or equal setInterval value
}

void loop() {

BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
delay(2000);

}`

@vekexasia
Copy link

@alx2k what pin are you using on the esp32?

@alx2k
Copy link
Author

alx2k commented Jun 24, 2020

Relay is connected to pin 22 by default (D1)
Emitter is connected to pin 11 (D3)

@vekexasia
Copy link

for some reason this code was working for me, then I redid the cabling and it does not work anymore. Wondering if the esp32 pin for data makes any difference.

@alx2k
Copy link
Author

alx2k commented Jun 25, 2020

Have you tried changing this line to other pins in your board?

const uint8_t signalPin = 17; // The number of the pin with the output signal

on the other hand, which board are you using?

@vekexasia
Copy link

hey @alx2k thanks for answering me. This is driving me nut. I spent countless hours now trying to get it working (again). I even inspected the wave form via audacity. Would you mind giviing me a hand ? You can write me on my nickname @gmail or on telegram @el_bau ?

I would really appreciate it.

@fredilarsen
Copy link
Owner

Well, this must be a record in delayed response, I did not see any email notifications at the time. I changed to a priority email account now to avoid this in the future.

Thank you for you interest and additions. And thanks for sharing the code as well.
I see this can be a great addition if modifying a charging cable, getting full funtionality into the cable, powered by a battery.

In my case I did not want to modify my mint-condition cable or the charger, so I made another solution. I have put the RF code in this repo into a class for less code in the main program, and have a pushbutton that increments a counter by MQTT (see my MQTT repo) to control my local Home Assistant installation to utilize the integration with the Tesla web API to unlock the cable. This also is triggered when I open the garage door remotely if the cable is plugged in, making sure the car is ready to go when I arrive in the garage shortly after.

@fredilarsen fredilarsen added enhancement New feature or request wontfix This will not be worked on labels Aug 29, 2020
@fredilarsen fredilarsen changed the title Changed version of your code Unlocking charge cable by wire Aug 29, 2020
@fredilarsen
Copy link
Owner

I did change the title of this request to make it easier to find, and I will leave it here for others to see.

One comment to people not knowing what PP is: This is one of the thin signal wires in the charge cable.

@fredilarsen fredilarsen changed the title Unlocking charge cable by wire Unlocking charge plug by wire Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants