A couple of years ago, I acquired much larger and much more expensive toy, an all-wheel drive, full auto-pilot Tesla Model-X SUV, so of course, I want to write Perl code to access and manipulate it.
In the ensuing two years, I developed several microcontroller-based devices for the car, including one that knows where the car is, and its battery charge and state, and dispslays this information via an LED light strip and an OLED screen inside of my garage, along with an audible alarm that sounds for 1/8th of a second every three seconds if the battery is below a certain threshold so I don't forget to plug the charger in.
The microcontroller speaks to a Raspberry Pi who's job it is to fetch data from the Tesla API for my car, and to present that data to the microconroller, over Wifi. The software on the Pi is of course written in Perl, but because I couldn't figure out how to write the Tesla API authentication mechanism in Perl, I used Tim Dorssers TeslaPy Python library, and wrapped it for those calls.
Not anymore! We can now talk to the Tesla API via Perl!
I've officially released Tesla::Vehicle, which inherits from my other new related distribution, Tesla::API.
Upon first attempt to fetch data from Tesla, we will generate a URL that you must browse through to in a browser, authenticate into your Tesla account, and then paste back the ensuing URL you are redirected to into the console. After that, all access tokens are automatically used and updated when needed. My software never has any access or knowledge of your Tesla account credentials, which is the way I wanted this designed.
Thereafter, it's clear sailing!
The documentation is pretty elaborate about what the software can do so please check it out. For Tesla::Vehicle, there are methods to access aggregate data, sections of the aggregate data, and for several specific attributes that I use myself, I've added methods for them directly. More will be added as time goes on.
Features:
api()
) to access data from endpoints that don't yet have a direct methodwake()
). For calls that require the car to be awake, you can set auto_wake
and we'll wake the car ourselves (disabled by default)new()
or id()
Todo: The main one is adding methods that allow control of the functionality of the car. The only one implemented thus far is wake()
. I'll also be adding more direct attribute retrieval methods. For now, use the aggregate methods and pull the data out of the return values yourself. There are also a few minor issues, primarily related to the handling of Tesla API timeouts.
How 'bout some code and output:
use warnings;
use strict;
use Tesla::Vehicle;
my $car = Tesla::Vehicle->new(auto_wake => 1);
printf(
"My Tesla account has my car registered with the name '%s'.\n",
$car->name
);
printf(
"My car is in gear %s and is currently going %d MPH and my odometer is %d\n",
$car->gear,
$car->speed,
$car->odometer
);
printf(
"My latitude is %f, longitide is %f, my heading is %d degrees and its using %.2f kWh/mile\n",
$car->latitude,
$car->longitude,
$car->heading,
$car->power
);
printf(
"My dashcam is %s, sentry mode is %s and I %s currently near my vehicle\n",
$car->dashcam,
$car->sentry_mode ? 'enabled' : 'disabled',
$car->user_present ? 'am' : 'am not'
);
printf(
"My battery is at %d%%, and is %s charging at %.2f volts pulling %.2f Amps\n",
$car->battery_level,
$car->charging_state ? 'currently' : 'not',
$car->charger_voltage,
$car->charge_actual_current
);
if ($car->battery_level >= $car->charge_limit_soc) {
print "The charger is connected but disabled due to set maximum charge level reached\n";
}
printf(
"My steering wheel warmer is %s, passenger seat warmer is %s, and Bio Weapon mode is %s\n",
$car->heater_steering_wheel ? 'on' : 'off',
$car->heater_seat_passenger ? 'on' : 'off',
$car->bioweapon_mode ? 'on' : 'off'
);
printf(
"The temperature inside the car is %dC and outside it's %dC, and climate control is %s\n",
$car->temperature_inside,
$car->temperature_outside,
$car->is_climate_on ? 'on' : 'off'
);
Output:
My Tesla account has my car registered with the name 'Dream machine'.
My car is in gear P and is currently going 0 MPH and my odometer is 49066
My latitude is XX.XXXXXX, longitide is -XXX.XXXXXX, my heading is 229 degrees and its using 0.00 kWh/mile
My dashcam is Unavailable, sentry mode is disabled and I am not currently near my vehicle
My battery is at 94%, and is currently charging at 0.00 volts pulling 0.00 Amps
The charger is connected but disabled due to set maximum charge level reached
My steering wheel warmer is off, passenger seat warmer is off, and Bio Weapon mode is off
The temperature inside the car is 17C and outside it's 13C, and climate control is off
]]>
If you have any information on the release procedure for Strawberry, or know anyone on that team I might be able to contact to get things moving forward again, please let me know.
This release contains one significant new feature, the ability to use Powershell as the shell when opening or using a Perl. In the UI, when you "Open" your current Perl, or "use" any Perl you have installed, if the "Use Powershell" option is checked, instead of a cmd.exe shell, you'll be presented with a Powershell one instead (same applies for the command line berrybrew use $version
.
The other changes in this release enhance the unit testing infrastructure, and the tests themselves.
Other notable changes since my last blog post:
berrybrew associate
command now has an alias of assoc
for fewer keystrokesupgrade
command. It's now recommended to use the Installer to manage upgradesNotable changes:
I've just got a new full time job, programming in Perl... finally, after several years of looking for that perfect work environment. Some of it will be on Windows (which I haven't used except for developing berrybrew
), so I'm actually looking forward to using my own software, especially how useful its become thanks to the new UI I've developed.
Happy Perling!
-stevieb
]]>Major changes include:
UI:
Installer:
Functionality:
For all other changes, please refer to the Changes file.
Cheers!
-stevieb
]]>To further, as the author of berrybrew who relies on several aspects of the site to manage Perls, might I be included in advance of site changes so I might better prepare?
]]>I have been working tirelessly on the newest version of berrybrew, and thought there's no better day to release it.
It brings significant new features:
New Features
associate
command, allowing berrybrew
to manage .pl
file associationsberrybrew-refresh
command, to be run after switching perls. No more having to re-open command line windowsoptions
command, allows changing configuration options at runtimebb
command, which is simply a short-hand form for berrybrew
PATH
environment variableinfo
command which displays various internal directory path informationUI
The UI is automatically installed by the installer. It starts and resides hidden in the System Tray until it is needed. Simply click the berrybrewUI
icon to bring up a Windows Form window. You can install, remove and switch between Perl instances.
When switching Perls using the UI, if you have open CLI windows, you still need to run berrybrew-refresh
or open a new CLI window to refresh the path information.
To exit the berrybrewUI
, right-click on the System Tray icon, and click Exit
.
Installer
There are several enhancements to the installer:
We properly check for existing installations, and ask confirmation questions on the actions, depending on information about the previous install. In some cases, we'll ask to do a direct upgrade, in others, we'll ask if we can simply disable the old version before installing the new. See caveats below.
We now ask for the directory location of the Perl instance directory (internally referred to as root_dir
). If you specify a location that a previous berrybrew
used, we'll merrily inherit all of the previously installed Perls.
Uninstall is available through Add/Remove programs
UI provides select-able options to 1) install the most recent version of Perl, 2) start the UI at system startup, 3) allow berrybrew
to manage .pl
file association
Caveats: If you have a previous version of berrybrew
where you've changed any of the default configuration variables in the config.json
file, you will have to manually update these options after install of the new version. Simply run berrybrew options
on the new version to see what values are set. Then, open up your previous berrybrew's config.json
file, and for each difference, simply run berrybrew options directive value
where directive
is the name of the option, and value
is the value from the old config file. This will be automated in a future release.
File Association
You can now allow berrybrew
to manage the .pl
file association. We implement this in a similar way to Unix, in which when we're managing this association, the system will use the first perl
found in the PATH
environment variable.
berrybrew associate
berrybrew associate set
berrybrew associate unset
Development Information
build_api.bat
, build_binary.bat
and build_ui.bat
. Left in place the build.bat
script, which performs all three actionsHKLM\Software\berrybrew-build
and HKLM\Software\berrybrew-test
)Mozilla has opened up a new IoT Platform, and I'm wondering if it'd be worth the time to provide a Perl interface to it or not.
Thoughts?
]]>Some changes were for development and testing of the software itself, a couple of features were added due to community requests, and yet more were requested by a client.
Here's a summary of the new features:
Management of external Perl installations; Using the new berrybrew virtual
command, one can bring in other installations of Perl for management under berrybrew
. For example, if you have an ActiveState Perl installed on the system, you can virtualize it under berrybrew
, and use
or switch
to it just like any of the portable Strawberry Perl's we normally manage. This means that you can switch over to your system Perl when needed, without having to modify PATH
, or temporarily disabling berrybrew
Unattended installations are now possible. We no longer prompt for user acceptance when running the initial configuration
New quick
argument to berrybrew switch
; This allows you to switch to a different Perl instance persistently without having to close the existing CLI window and opening a new one (note: some binaries and features may not work correctly. If you run into problems, simply open a new window)
Export and import modules from one Perl instance to another; berrybrew modules export
and berrybrew modules import
will dump a list of all installed CPAN distribution names from one Perl and install it on others. The export files can be edited at will before re-importing, and you can even create your own module list files to use as you see fit. Using this feature, in conjunction with berrybrew clone
allows you to easily set up template Perl instances for very quick Perl platform setup
Ability to change the location where File::HomeDir
points to; you can switch between the Windows home directory location, or the default location that Strawberry Portable editions set
Here's an example of the new berrybrew virtual
feature:
Configure an external Perl as a berrybrew-managed Perl ("active-state" is just a name you desire that'll show up in berrybrew list
and berrybrew available
):
> berrybrew virtual active-state
Specify the path to the perl binary: c:\perl64\bin
Specify the library path: c:\perl64\site\bin
Specify an additional path:
Successfully registered virtual perl active-state
Check that it took:
> berrybrew list
5.16.3_64 *
5.10.1_32
bb-as-test
active-state
> berrybrew available
... snip for brevity
5.16.3_64 [installed] *
5.16.3_32
5.14.4_64
5.14.4_32
5.12.3_64
5.12.3_32
5.10.1_32 [installed]
5.8.9_32
bb-as-test [installed] [custom]
active-state [installed] [virtual]
Verify we're still using the previous Perl:
> perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-multi-thread
Use the new one:
> berrybrew use active-state
perl-active-state
==============
Microsoft Windows [Version 10.0.17763.107]
(c) 2018 Microsoft Corporation. All rights reserved.
<berrybrew use active-state>: run "exit" leave this environment
Verify we're using the system's ActiveState Perl:
> perl -v
This is perl 5, version 26, subversion 3 (v5.26.3) built for MSWin32-x64-multi-thread
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2018, Larry Wall
Binary build 0000 [fde9aa8a] provided by ActiveState http://www.ActiveState.com
Built Jul 31 2019 01:43:08
Once the new sub-shell is closed, confirm everything is sane:
> exit
Exiting <berrybrew use active-state>
> perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-multi-thread
It doesn't need to be ActiveState Perl. Any external Perl installed on the system can be used. All we need is a path to the perl.exe
binary, and any library paths (if available).
It's currently a two-step process.
First, berrybrew switch
into the Perl instance you want to export the module list from, then...
berrybrew modules export
This will create a text document in a newly created modules
directory within your Perl installation directory (by default, C:\berrybrew
), named after the version of Perl you exported the module list from (eg: 5.20.3_64
). This file has a single distribution name per line.
You can go ahead and edit this file (remove or add as many distribution names as you like), then when you're ready to import into a different Perl instance, simply berrybrew switch
to it (note that as always, when switching Perls, you must close the command window and open a new one), then:
berrybrew modules import
That will display a list of all available export lists:
run the command with one of the following options:
5.16.3_64
5.20.3_64
...simply do what it says there:
berrybrew modules import 5.20.3_64
This can take a very, very long time, so it's advised to only import on a Perl instance that's newer than Perl you exported from. That, or significantly clean the file up for unneeded distributions.
Another benefit to this system, is that you can manually create a module "bundle" file within the mentioned "modules" directory, and add all distributions you prefer on all of your Perls. So:
C:\berrybrew\modules\base_modules_template
fileberrybrew modules import base_modules_template
to have your custom distribution list installed automaticallyYou can remove all exported files by using the berrybrew clean modules
command, but beware that if you have any manually created export files per above, they will be removed as well. I've got an issue open for the next release so that clean modules
leaves any custom files in place.
Most of the other changes were quite minor this round, mainly back-end stuff, doc updates/fixes and test additions/modifications, along with an updated perls.json
file with the newly released 5.30 version.
Feedback, as always, is welcome (as are any bug tickets).
Enjoy!
-stevieb
]]>I've been fortunate enough to receive your kind work, and for that, I'm very thankful.
It's because of you and people like you that will keep Perl going for another 20 years.
Thank you for your diligence and extremely strong efforts. Although many may not show notice, I'm positive they take it.
Please keep up the great work; your efforts aren't lost.
-stevieb
]]>Absolutely love it.
My core dists have 98%+ coverage, and the reason behind not having 100% is due to the fact that I've got a "_vim_placeholder()" type sub that is untested, because it's literally just a stop-gap between code and POD in my IDE.
Guess I'll rectify that by throwing a test at it.
Very glad you've brought this new MCPAN feature to the forefront here.
-stevieb
]]>You can learn more about it and purchase it here on Leanpub.
As one person mentioned to me "Finally, a release from the shackles of Raspbian and Python!".
Timm and I want to thank all of the financial contributors who got this project off the ground!
]]>I'm very excited, and even before we hit the target, Timm and I had been in communication preparing for, and even commencing some of the book's aspects.
I would like to personally thank everyone for their support, and want to give Gabor a shout-out for monitoring the progress of the fundraiser, and making it prevalent in the Perl Weekly for those couple of weeks there. We noticed a significant spike in activity following the release of the newsletter. Thank you everyone!
-stevieb
]]>We have decided to set a stretch goal. If we surpass our minimum $2,500 USD and get up to $4,000 USD, we will be adding three new chapters.
Timm will add one on Infrared Remote Control, and another focusing on using MQTT: a machine-to-machine (M2M)/"Internet of Things" connectivity protocol.
I will add a chapter that will step-by-step explain how to read and understand the relevant portions of a datasheet for an Integrated Circuit (IC) or some form of sensor, how to communicate/manipulate and otherwise act on the device's registers in C, the process of converting the working C code into XS, and finally creating a new Perl distribution for the device.
Thank you for all of the support!
-stevieb
]]>Timm will be writing the bulk of the content using various distributions including my RPi::WiringPi along with all its related distributions, and I will be adding at least one chapter to cover my indoor grow room single-webpage environment controller, as well as performing editing duties and testing of the code.
We've been working together for a couple of weeks now, and today, I'm proud to announce the official launching of the fundraiser for the new book.
Whether you're interested in working on the Raspberry Pi, or just want to donate to a good cause for other Perl hackers, please have a look.
Thanks!
]]>