-
Notifications
You must be signed in to change notification settings - Fork 19
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
Comments
@alx2k what pin are you using on the esp32? |
Relay is connected to pin 22 by default (D1) |
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. |
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? |
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. 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. |
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. |
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:
`/*
*/
// 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);
}`
The text was updated successfully, but these errors were encountered: