Skip to content

Commit

Permalink
Server:
Browse files Browse the repository at this point in the history
- added timestamp to gcm notifications
- added gcm documentation
- updated CPAN module info
- updated version tag to 2.2.1
  • Loading branch information
dexterbg committed Nov 16, 2015
1 parent 72f0561 commit ecac35b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
9 changes: 4 additions & 5 deletions client/README
Expand Up @@ -5,18 +5,17 @@ Open Vehicle Monitoring System
Perl modules
============

Install the following perl modules from CPAN:
The following perl modules from CPAN are used by the clients:

EV
AnyEvent
Config::IniFiles
DBI
DBD::MySQL
Digest::MD5
Digest::HMAC
Crypt::RC4::XS
MIME::Base64

Install modules using cpanminus:
cpanm Config::IniFiles Digest::MD5 Digest::HMAC Crypt::RC4::XS MIME::Base64


The clients
===========
Expand Down
30 changes: 26 additions & 4 deletions docs/HOWTO.server.txt
@@ -1,11 +1,14 @@
HOWTO Setup an OVMS server
==========================


0. DO I NEED THIS?

You don't need to run your own OVMS server.
You can just use the public Open Vehicles OVMS server.
The choice is yours.


1. PREREQUISITES

You'll need a Linux. OSX, BSD, or other flavour of Unix, server with a public IP address and
Expand All @@ -18,20 +21,36 @@ to be able to create a database and accounts.
This could conscievably run on a windows server, but you are on your own ;-)
[ let us know instructions if you manage to get it running ]


2. MODULE INSTALLATION

Install the following perl modules from CPAN:

EV
AnyEvent
Config::IniFiles
DBI
DBD::MySQL
Digest::MD5
Digest::HMAC
Crypt::RC4::XS
MIME::Base64

DBI
DBD::mysql
EV
AnyEvent
AnyEvent::HTTP
AnyEvent::HTTPD
HTTP::Parser::XS
Data::UUID
Email::MIME
Email::Sender::Simple
Net::SSLeay
JSON::XS

Install modules using cpanminus:
cpanm Config::IniFiles Digest::MD5 Digest::HMAC Crypt::RC4::XS MIME::Base64 \
DBI DBD::mysql EV AnyEvent AnyEvent::HTTP AnyEvent::HTTPD HTTP::Parser::XS \
Data::UUID Email::MIME Email::Sender::Simple Net::SSLeay JSON::XS


3. MYSQL SETUP

Create a mysql database "openvehicles" and use the ovms_server.sql script from github (server
Expand All @@ -51,6 +70,7 @@ Insert a record into the ovms_cars table, to give you access to your own car:
Obviously, change the vehicleid, carpass and userpass as necessary. The only required fields are
vehicleid and carpass.


4. OVMS_SERVER ACCESS TO MYSQL

Create a file ovms_server.conf which defines the access to the mysql database:
Expand All @@ -71,12 +91,14 @@ Test the connection with:
If you get "ERROR 1044 (42000): Access denied", fix it before proceeding. The most likely cause
is a mistake in your mysql user grant rights.


5. RUN THE SERVER

Get the ovms_server.pl code from github and run it with:

$ ./ovms_server.pl


6. ENJOY

Any questions/comments, please let us know.
Expand Down
22 changes: 22 additions & 0 deletions server/README
@@ -1,4 +1,5 @@
Open Vehicle Monitoring System
==============================


The Server
Expand All @@ -18,3 +19,24 @@ file suitably configured, the ovms_server.sql database tables in a mysql databas
the *.vece files (to convert error code to messages for different vehicle types).

The other scripts are purely for development and testing purposes.


Android Push Notifications
==========================

...are based on Google Cloud Messaging (GCM).

To be able to send push notifications to Android devices, you need to register a GCM project:

- Log in to your Google account
- Open https://developers.google.com/mobile/add
- Select platform "Android"
- Enter an arbitrary project name, e.g. "MyOvmsServer"
- Package name should be "com.openvehicles.OVMS"
- Activate "Cloud Messaging" and generate the key
- Note the API key and project number (= GCM sender ID)

Enter the API key into your ovms_server.conf and the project number (GCM sender ID) into the
App vehicle configuration.


3 changes: 3 additions & 0 deletions server/ovms_server.conf
Expand Up @@ -7,3 +7,6 @@ pass=<put the mysql password here>
enabled=0
interval=10
sender=notifications@openvehicles.com

[gcm]
apikey=<your GCM API key, see README>
7 changes: 6 additions & 1 deletion server/ovms_server.pl
Expand Up @@ -24,6 +24,7 @@
use Socket qw(SOL_SOCKET SO_KEEPALIVE);
use Email::MIME;
use Email::Sender::Simple qw(sendmail);
use POSIX qw(strftime);

use constant SOL_TCP => 6;
use constant TCP_KEEPIDLE => 4;
Expand All @@ -32,7 +33,7 @@

# Global Variables

my $VERSION = "2.1.1-20121216";
my $VERSION = "2.2.1-20151116";
my $b64tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
my $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
my %conns;
Expand Down Expand Up @@ -1193,6 +1194,7 @@ sub svr_timeout
sub push_queuenotify
{
my ($vehicleid, $alerttype, $alertmsg) = @_;
my $timestamp = strftime "%Y-%m-%d %H:%M:%S", gmtime;

if ($alerttype eq 'E')
{
Expand All @@ -1209,6 +1211,7 @@ sub push_queuenotify
$rec{'vehicleid'} = $vehicleid;
$rec{'alerttype'} = $alerttype;
$rec{'alertmsg'} = $alertmsg;
$rec{'timestamp'} = $timestamp;
$rec{'pushkeytype'} = $row->{'pushkeytype'};
$rec{'pushkeyvalue'} = $row->{'pushkeyvalue'};
$rec{'appid'} = $row->{'appid'};
Expand Down Expand Up @@ -1407,12 +1410,14 @@ sub gcm_tim
my $vehicleid = $rec->{'vehicleid'};
my $alerttype = $rec->{'alerttype'};
my $alertmsg = $rec->{'alertmsg'};
my $timestamp = $rec->{'timestamp'};
my $pushkeyvalue = $rec->{'pushkeyvalue'};
my $appid = $rec->{'appid'};
AE::log info => "#$fn - $vehicleid msg gcm '$alertmsg' => $pushkeyvalue";
my $body = 'registration_id='.uri_escape($pushkeyvalue)
.'&data.title='.uri_escape($vehicleid)
.'&data.message='.uri_escape($alertmsg)
.'&data.time='.uri_escape($timestamp)
.'&collapse_key='.time;
http_request
POST=>'https://android.googleapis.com/gcm/send',
Expand Down

0 comments on commit ecac35b

Please sign in to comment.