Skip to content

Unlocking charge plug by wire #1

Open
@alx2k

Description

@alx2k

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);

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions