[Ovmsdev] Doubs in implementation with nodejs.

Michael Balzer dexter at expeedo.de
Sat Aug 6 17:34:14 HKT 2022


Gregg,

I've had a look at that module (https://github.com/birkir/ovms-client): 
the example code is wrong. As you didn't post any of your actual code, I 
can only assume you try to base your code on that example.

First of all, the connect() call is running asynchronously, and you must 
not send commands until the "connected" event has been emitted.

Second & more importantly for your command application, the send() 
method does not work as shown in the example ("send('stat')"). You need 
to construct the actual MP command for send.

Third & finally, you need to subscribe to the "commandReceived" event if 
you want to receive the results (instead of parsing the "raw" messages 
yourself).

Here's a complete working example code using that module sending both a 
shell and a lock command:

    const { OVMSClient } = require('ovms-client');

    // host, port, vehicle id, password
    const client = new OVMSClient('ovms.dexters-web.de', 6867, 'xxx',
    'xxx');

    // connect
    client.connect();

    // subscribe to command responses:
    client.on('commandReceived', response => {
       let [ command, result, message ] = response.split(',');
       console.log('*** response: command', command, "result", result);
       if (message) {
         console.log(message.replace(/\r/g, String.fromCharCode(10)));
       }
    });

    client.on('connected', callback => {

       // send shell command
       console.log('*** send command: 7,stat');
       client.send('7,stat');

       // send lock command (with PIN 1234)
       console.log('*** send command: 20,1234');
       client.send('20,1234');

    });


Example run:

    balzer at leela:~/ovms/nodejs> DEBUG=* node test.js
       OVMS connected to socket +0ms
       OVMS Server authentication OK. +17ms
       OVMS RX: MP-S 0 gKmpSDl8krIShUcPcIYFHO N6LiQqThPvJEUvvQV4f8Kg==
      +1ms
    *** send command: 7,stat
    *** send command: 20,1234
    *** response: command 7 result 0
    Not charging
    SOC: -
    Ideal range: 0km
    CAC: 120.0Ah

    *** response: command 20 result 1
    ^C


Note: command 20 returned "failed" (result 1) here, because the test 
module on my bench cannot lock a car.

This was the module log for that session:

    I (2192998) ovms-server-v2: Incoming Msg: MP-0 Z1
    I (2192998) ovms-server-v2: One or more peers have connected
    I (2193008) ovms-server-v2: Incoming Msg: MP-0 C7,stat
    I (2193008) ovms-server-v2: Send MP-0 c7,0,Not charging|SOC: -|Ideal
    range: 0km|CAC: 120.0Ah
    I (2193048) ovms-server-v2: Incoming Msg: MP-0 C20,1234
    I (2193048) v-vweup: CommandLock
    I (2193048) ovms-server-v2: Send MP-0 c20,1


So the module is actually working nicely, it's just got a poor usage 
example.

Be aware the module does not yet support TLS encryption though, you 
should add that before actually using it.

Regards,
Michael


Am 04.08.22 um 06:05 schrieb gregg hansen:
> Just to be sure, we’ll set some time frames and I’ll park the car
>
> On Wed, Aug 3, 2022 at 11:03 PM Mark Webb-Johnson 
> <mark at webb-johnson.net> wrote:
>
>     Gregg,
>
>     I checked for August 2022, ET225567 I find (redacted as necessary):
>
>         2022-08-04 03:34:52.589231 UTC info  OVMS::Server::ApiV2: #10
>         A ET225567 rx msg C 20,
>         2022-08-04 03:34:52.590298 UTC info  OVMS::Server::ApiV2: #10
>         A ET225567 cmd req for ET225567 (queue now 10)
>         2022-08-04 03:34:52.590552 UTC info  OVMS::Server::ApiV2: #25
>         C ET225567 tx msg C 20,
>         2022-08-04 03:34:55.185066 UTC info  OVMS::Server::ApiV2: #25
>         C ET225567 rx msg c 20,0
>         2022-08-04 03:34:55.185657 UTC info  OVMS::Server::ApiV2: #25
>         C ET225567 cmd rsp to #10 for ET225567 (queue now )
>         2022-08-04 03:34:55.185739 UTC info  OVMS::Server::ApiV2: #10
>         A ET225567 tx msg c 20,0
>
>
>     No way of knowing if that was from the app or the library, but the
>     message sequence is correct and the command was acknowledged by
>     the car as successfully executed. Command #20 is ‘lock car’.
>
>     Regards, Mark
>
>>     On 4 Aug 2022, at 11:36 AM, gregg hansen <gregg at rabbitev.com> wrote:
>>
>>     If there is a better library to try let me know.  We tried a
>>     couple before we landed on that one.
>>
>>     We only test with one vehicle - ET225567
>>
>>     This is my fleet vehicle, so there’s a decent chance it will be
>>     in use.
>>
>>     Tomorrow we’ll try some tests and send some timestamps
>>
>>     On Wed, Aug 3, 2022 at 10:31 PM Mark Webb-Johnson
>>     <mark at webb-johnson.net> wrote:
>>
>>         Gregg,
>>
>>         OK. That is clearer. At a glance, the library seems ok, but I
>>         haven’t worked with that one previously, or even knew of it.
>>
>>         Can you let me know a vehicle ID, and UTC timestamp, of one
>>         of your connections and attempted unlocks? I can then check
>>         the server logs.
>>
>>         Or let me know vehicle ID, try it now, and I can monitor.
>>
>>         Regards, Mark.
>>
>>
>>>         On 4 Aug 2022, at 11:21 AM, gregg hansen
>>>         <gregg at rabbitev.com> wrote:
>>>
>>>         This is the library we are using it encrypt some data and
>>>         use the MP commands to call some functionalities to the car
>>>         with this we retrieve some data like the battery status.
>>>
>>>         NPM Lib
>>>         https://www.npmjs.com/package/ovms-client?activeTab=readme
>>>         Github
>>>         https://github.com/birkir/ovms-client
>>>         (in the Github is an instruction that explains how does the
>>>         library works)
>>>
>>>         It has a function to send shell commands like 'stat'
>>>         commands, but when we send a command looks like the car is
>>>         receiving the command but it seems like the car gets the
>>>         commands but does not interact with it.
>>>
>>>         There is other function that allows us to send raw data to
>>>         the car that is the MP commands, but in this case when I
>>>         send a Raw command this don't connect with the car and its
>>>         stock loading waiting for a response that is never returned.
>>>
>>>         I have been trying to make a script that lets me connect to
>>>         the car, but I only could connect to the ovms-server that
>>>         let us make the connection with the car, but I can not set
>>>         the carId and password on that socket to make the connection
>>>         to the car.
>>>
>>>         We are using OVMS v2 in the cars.
>>>
>>>         Thanks for your help and we are going to be glad to read you
>>>         answers
>>>
>>>         On Wed, Aug 3, 2022 at 10:07 PM Mark Webb-Johnson
>>>         <mark at webb-johnson.net> wrote:
>>>
>>>             Gregg,
>>>
>>>             We really need to know exactly what he is doing, and
>>>             with what protocols.
>>>
>>>             From the way you seem to describe it, you:
>>>
>>>              1. Have a custom app, in react native
>>>              2. You have a custom server, in NodeJS
>>>              3. You presumably have some custom protocol/api between
>>>                 your app and server
>>>              4. Your NodeJS server is talking to the OVMS server
>>>                 using your own implementation of v2 protocol
>>>
>>>
>>>             Is that correct? If so, then #4 is the only issue. The
>>>             V2 protocol is fairly well documented, here:
>>>
>>>                 https://docs.openvehicles.com/en/latest/protocol_v2/index.html
>>>
>>>
>>>             It is proprietary and the initial negotiation is
>>>             complicated, but if you have established the crypto
>>>             connection and received the data, then you have done the
>>>             hard part. Issuing commands should be easy.
>>>
>>>             In v2 protocol, locking/unlocking is performed via the
>>>             “C” command.
>>>
>>>             Probably easiest to look at the sample code in the iOS
>>>             or Android Apps to see how that is done. For iOS, see:
>>>
>>>                 https://github.com/openvehicles/Open-Vehicle-iOS/blob/master/OpenVehicleApp/ovms/ovmsAppDelegate.m
>>>
>>>                 (The commandIssue method, and how it is called)
>>>
>>>
>>>             Regards, Mark.
>>>
>>>>             On 3 Aug 2022, at 11:03 PM, gregg hansen
>>>>             <gregg at rabbitev.com> wrote:
>>>>
>>>>             Pablo has not been able to access the list.  He is
>>>>             getting authentication errors, so while he works
>>>>             through that I thought I would answer for him...
>>>>
>>>>                 "The MP commands are the raw data I am trying to
>>>>                 send to the car to open and close the car."
>>>>
>>>>             The devices are using the V2 server, so I think fixed
>>>>             MP commands make the most sense.  Pablo is trying to
>>>>             figure out how to make that work, and so far has not
>>>>             been successful.
>>>>
>>>>
>>>>
>>>>             On Sun, Jul 31, 2022 at 2:26 AM Michael Balzer
>>>>             <dexter at expeedo.de> wrote:
>>>>
>>>>                 Pablo,
>>>>
>>>>                 a bit more information on how you connect to the
>>>>                 car would be helpful here.
>>>>
>>>>                 Arbitrary remote shell command execution is
>>>>                 supported by the module's HTTP API (/api/execute),
>>>>                 the module's SSH server, the "V2 protocol" server
>>>>                 via MP command 7 and any "V3" (MQTT) server via the
>>>>                 /client/command topic scheme. Plus there's a
>>>>                 secondary (non-standard) HTTP command API available
>>>>                 on my server ovms.dexters-web.de
>>>>                 <http://ovms.dexters-web.de/> (public API of my
>>>>                 custom web shell).
>>>>
>>>>                 Lock & unlock are also available as fixed MP
>>>>                 commands (20,22) on a V2 server, along with a set
>>>>                 of other standard App calls. These do not run via
>>>>                 the shell but translate to direct internal execution.
>>>>
>>>>                 Command execution has not yet been implemented for
>>>>                 the "V2" server's HTTP API. But you can of course
>>>>                 implement that if you use that API.
>>>>
>>>>                 Docs:
>>>>
>>>>                   * https://docs.openvehicles.com/en/latest/components/ovms_webserver/docs/index.html#authorization
>>>>                   * https://docs.openvehicles.com/en/latest/userguide/console.html#ssh-console
>>>>                   * https://docs.openvehicles.com/en/latest/protocol_v2/commands.html#execute-sms-command
>>>>                       o https://docs.openvehicles.com/en/latest/protocol_v2/commands.html#lock-car
>>>>                       o https://docs.openvehicles.com/en/latest/protocol_v2/commands.html#unlock-car
>>>>                   * http://lists.openvehicles.com/pipermail/ovmsdev/2018-July/012641.html
>>>>                   * http://lists.openvehicles.com/pipermail/ovmsdev/2018-July/012696.html
>>>>                   * https://docs.openvehicles.com/en/latest/protocol_httpapi/requests.html#not-yet-implemented
>>>>
>>>>                 Which one are you referring to?
>>>>
>>>>                 Regards,
>>>>                 Michael
>>>>
>>>>
>>>>                 Am 29.07.22 um 19:28 schrieb Pablo Cabrera:
>>>>>                 Hello OVMS team, we are currently working with an
>>>>>                 implementation with OVMS in a react native app
>>>>>                 with a NodeJS back-end.
>>>>>                 Currently we can connect with the cars and rescue
>>>>>                 some data like the status of the battery or GPS
>>>>>                 location, but now we need to send commands to lock
>>>>>                 and unlock the cars from the same app, when we
>>>>>                 send a command I get a response that the command
>>>>>                 is received in the car, but the command is not
>>>>>                 executed in the bash.
>>>>>
>>>>>                 I don't know if you can send me more info
>>>>>                 about how to make the car receive bash
>>>>>                 commands from remote connections, or how can I
>>>>>                 send it from the NodeJs server into the bash of
>>>>>                 the car.
>>>>>
>>>>>                 Thanks for your time and help.
>>>>>
>>>>>                 _______________________________________________
>>>>>                 OvmsDev mailing list
>>>>>                 OvmsDev at lists.openvehicles.com
>>>>>                 http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>>>>
>>>>                 -- 
>>>>                 Michael Balzer *Helkenberger Weg 9 * D-58256 Ennepetal  <https://www.google.com/maps/search/Helkenberger+Weg+9+*+D-58256+Ennepetal?entry=gmail&source=g>
>>>>                 Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
>>>>
>>>>                 _______________________________________________
>>>>                 OvmsDev mailing list
>>>>                 OvmsDev at lists.openvehicles.com
>>>>                 http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>>>>
>>>>
>>>>
>>>>             -- 
>>>>
>>>>             RabbitEV
>>>>             Driving Electric Cars
>>>>             RabbitEV.com <http://rabbitev.com/>
>>>>             _______________________________________________
>>>>             OvmsDev mailing list
>>>>             OvmsDev at lists.openvehicles.com
>>>>             http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>>>
>>>             _______________________________________________
>>>             OvmsDev mailing list
>>>             OvmsDev at lists.openvehicles.com
>>>             http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>>>
>>>         _______________________________________________
>>>         OvmsDev mailing list
>>>         OvmsDev at lists.openvehicles.com
>>>         http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>>
>>         _______________________________________________
>>         OvmsDev mailing list
>>         OvmsDev at lists.openvehicles.com
>>         http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>>
>>     _______________________________________________
>>     OvmsDev mailing list
>>     OvmsDev at lists.openvehicles.com
>>     http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>
>     _______________________________________________
>     OvmsDev mailing list
>     OvmsDev at lists.openvehicles.com
>     http://lists.openvehicles.com/mailman/listinfo/ovmsdev
>
>
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev

-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20220806/a2d21ddb/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20220806/a2d21ddb/attachment-0001.sig>


More information about the OvmsDev mailing list