Topics

Wifi FastClock


Andrew Deak
 

All

I have a Wifi Fastclock system and I like to interface it JMRI. I like the best way to interface my VB6 program to JMRI or Run my Wifi Modules from JMRI.


Thanks

Andrew Deak


Randall Wood <rhwood@...>
 

Are you making the logic for this fast clock, or did you purchase it?

I’m asking because the answers might be different based on that.

Randall

On Jun 18, 2020, at 11:44, Andrew Deak <adeakrr@...> wrote:

All

I have a Wifi Fastclock system and I like to interface it JMRI. I like the best way to interface my VB6 program to JMRI or Run my Wifi Modules from JMRI.


Thanks

Andrew Deak


Andrew Deak
 

Randall

 

I developed  a Wifi Fastclock system, see  http://www.modelrailroadcontrolsystems.com/wifi-ethernet-fast-clock-system/.

 

I developed a system for my own use and Seth Newman said we should offer to sell them. I do not make much money off each one, I just doing for fun.

 

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?

 

 

 

Thanks

 

Andrew Deak

 

 

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Thursday, June 18, 2020 5:23 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Are you making the logic for this fast clock, or did you purchase it?

 

I’m asking because the answers might be different based on that.


Randall



On Jun 18, 2020, at 11:44, Andrew Deak <adeakrr@...> wrote:

All

I have a Wifi Fastclock system and I like to interface it JMRI. I like the best way to interface my VB6 program to JMRI or Run my Wifi Modules from JMRI.


Thanks

Andrew Deak


Randall Wood <rhwood@...>
 

JMRI has a JSON protocol that can accept sync data from your device over a network socket, over RESTful HTTP, or over a WebSocket.

Try using curl or wget to post a JSON message to http://your-JMRI-server:12080/json/time (you should be able to post a message in the same JSON structure as received when you visit that URL in a web browser).

Randall

On Jun 18, 2020, at 20:05, Andrew Deak <adeakrr@...> wrote:



Randall

 

I developed  a Wifi Fastclock system, see  http://www.modelrailroadcontrolsystems.com/wifi-ethernet-fast-clock-system/.

 

I developed a system for my own use and Seth Newman said we should offer to sell them. I do not make much money off each one, I just doing for fun.

 

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?

 

 

 

Thanks

 

Andrew Deak

 

 

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Thursday, June 18, 2020 5:23 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Are you making the logic for this fast clock, or did you purchase it?

 

I’m asking because the answers might be different based on that.


Randall



On Jun 18, 2020, at 11:44, Andrew Deak <adeakrr@...> wrote:

All

I have a Wifi Fastclock system and I like to interface it JMRI. I like the best way to interface my VB6 program to JMRI or Run my Wifi Modules from JMRI.


Thanks

Andrew Deak


Bob M.
 

Andrew,

From the JMRI perspective, it seems to me that your mechanism might be considered to be comparable to the WiThrottle Server or the Web Server. Neither of these JMRI features are considered "DCC System"s, and both are built-in features of JMRI regardless of which DCC system is being used. Both of them are oriented to JMRI-related communication via WiFi- or IEEE 802.3-style networking. Your WiFi fast clock seems to follow that pattern. As such, my thought is that integrating your WiFi fast clock system into JMRI could be done in a way similar to these two JMRI implementations.

Here's a pertinent question:

What mechianism(s) do you think JMRI will use to "connect" to your WiFi fast clock system?

- Must the JMRI computer connect to and communicate with the Fast-clock-WiFi via the WiFi network?
- Is there one or more alternate communication method(s) available that JMRI must support? Such as via a USB cable?
- Is there any simultaneously-active combination of the above communication mechanisms which JMRI must or should support actively for a single WiFi fast clock installation?
- If more than one connection/communication option must be supported, are the options always "mutually-exclusive"?

These questions lead to ones related to how the user configures his JMRI system to address those options, plus any JMRI networking features he/she otherwise using. But I may mis-understand your mechanisms.

If I have a single JMRI computer, and I want to run JMRI's WiThrottleServer or WiFi-based Web Server or any of its other networked solutions via WiFi, then I have one WiFi network for WiThrottle Server and/or Web Server. I assume your WiFi fast clocks are operating on a separate WiFi network. What must I do with my JMRI computer to make your WiFi fast clock solution work _in parallel_ with my pre-existing WiThrottle Server and/or Web Server WiFi? Is it so simple as adding and configuring an additional WiFi adapter on the JMRI computer? If so, then it may be necessary for JMRI to include features to allow the user to select a specific WiFi adapter for WiFi fast clock operations.

And, if more than one WiFi and/or802.3-like network is available to JMRI, how does JMRI direct its support for existing networked features to act via one of the available? I've never noticed such a feature, and have never experienced such a challenge, but your system, if it acts as an additional network, will make it necessary to answer such questions.

Regards,
Bob M.


Paul Bender
 

Andrew,


On Jun 18, 2020, at 8:05 PM, Andrew Deak <adeakrr@...> wrote:

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?


There are multiple ways of doing this. You could, as Randall suggested, use one of the network protocols JMRI supports already  with fast clock support ( the restful Service Randall mentioned, or SRCP, or perhaps some other I am forgetting) or you could add code to JMRI that implements your existing solution and interacts with JMRI’s time base objects.

But let me ask this question: what do you want to provide the master clock in the system?  
Do you want JMRI to control the clocks?
Do you want your clock server to control JMRI’s clock?  

These are not mutually exclusive options and what you want will provide the guidance we need to give a better answer.

Paul


Andrew Deak
 

Paul

 

I want my program to control the clocks and interface into JMRI to update the throttles?

 

I could have JMRI be the master?

 

Thanks

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Paul Bender
Sent: Thursday, June 18, 2020 10:40 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Andrew,



On Jun 18, 2020, at 8:05 PM, Andrew Deak <adeakrr@...> wrote:

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?

 

There are multiple ways of doing this. You could, as Randall suggested, use one of the network protocols JMRI supports already  with fast clock support ( the restful Service Randall mentioned, or SRCP, or perhaps some other I am forgetting) or you could add code to JMRI that implements your existing solution and interacts with JMRI’s time base objects.

 

But let me ask this question: what do you want to provide the master clock in the system?  

Do you want JMRI to control the clocks?

Do you want your clock server to control JMRI’s clock?  

 

These are not mutually exclusive options and what you want will provide the guidance we need to give a better answer.

 

Paul




Andrew Deak
 

All

 

I tiring to Jason Http command. I tried this and it will not work? What the format?

 

http://localhost:12080/json/time/rate/4.0/

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Andrew Deak via groups.io
Sent: Thursday, June 18, 2020 10:44 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Paul

 

I want my program to control the clocks and interface into JMRI to update the throttles?

 

I could have JMRI be the master?

 

Thanks

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Paul Bender
Sent: Thursday, June 18, 2020 10:40 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Andrew,

 

On Jun 18, 2020, at 8:05 PM, Andrew Deak <adeakrr@...> wrote:

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?

 

There are multiple ways of doing this. You could, as Randall suggested, use one of the network protocols JMRI supports already  with fast clock support ( the restful Service Randall mentioned, or SRCP, or perhaps some other I am forgetting) or you could add code to JMRI that implements your existing solution and interacts with JMRI’s time base objects.

 

But let me ask this question: what do you want to provide the master clock in the system?  

Do you want JMRI to control the clocks?

Do you want your clock server to control JMRI’s clock?  

 

These are not mutually exclusive options and what you want will provide the guidance we need to give a better answer.

 

Paul

 


Bob Jacobsen
 

1) Was JMRI running on ‘localhost’ with it’s server started?

2) Did you try it using the curl or wget command, now a web browser?

Bob

On Jun 18, 2020, at 7:48 PM, Andrew Deak <adeakrr@...> wrote:

All



I tiring to Jason Http command. I tried this and it will not work? What the format?



http://localhost:12080/json/time/rate/4.0/



Andrew Deak



From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Andrew Deak via groups.io
Sent: Thursday, June 18, 2020 10:44 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock



Paul



I want my program to control the clocks and interface into JMRI to update the throttles?



I could have JMRI be the master?



Thanks



Andrew Deak



From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Paul Bender
Sent: Thursday, June 18, 2020 10:40 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock



Andrew,



On Jun 18, 2020, at 8:05 PM, Andrew Deak <adeakrr@...> wrote:

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.



The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?



For my own use I have interface to NCE Base stations(Networked)



I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?



There are multiple ways of doing this. You could, as Randall suggested, use one of the network protocols JMRI supports already with fast clock support ( the restful Service Randall mentioned, or SRCP, or perhaps some other I am forgetting) or you could add code to JMRI that implements your existing solution and interacts with JMRI’s time base objects.



But let me ask this question: what do you want to provide the master clock in the system?

Do you want JMRI to control the clocks?

Do you want your clock server to control JMRI’s clock?



These are not mutually exclusive options and what you want will provide the guidance we need to give a better answer.



Paul




--
Bob Jacobsen
@BobJacobsen


Randall Wood <rhwood@...>
 

You will not be able to set the JMRI fast clock using a browser, only see what the JMRI fast clock is currently set for.

I’ll have more details over the weekend.

Randall

On Jun 18, 2020, at 22:48, Andrew Deak <adeakrr@...> wrote:



All

 

I tiring to Jason Http command. I tried this and it will not work? What the format?

 

http://localhost:12080/json/time/rate/4.0/

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Andrew Deak via groups.io
Sent: Thursday, June 18, 2020 10:44 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Paul

 

I want my program to control the clocks and interface into JMRI to update the throttles?

 

I could have JMRI be the master?

 

Thanks

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Paul Bender
Sent: Thursday, June 18, 2020 10:40 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Andrew,

 

On Jun 18, 2020, at 8:05 PM, Andrew Deak <adeakrr@...> wrote:

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?

 

There are multiple ways of doing this. You could, as Randall suggested, use one of the network protocols JMRI supports already  with fast clock support ( the restful Service Randall mentioned, or SRCP, or perhaps some other I am forgetting) or you could add code to JMRI that implements your existing solution and interacts with JMRI’s time base objects.

 

But let me ask this question: what do you want to provide the master clock in the system?  

Do you want JMRI to control the clocks?

Do you want your clock server to control JMRI’s clock?  

 

These are not mutually exclusive options and what you want will provide the guidance we need to give a better answer.

 

Paul

 


Andrew Deak
 

Randall

 

Thanks

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Friday, June 19, 2020 7:33 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

You will not be able to set the JMRI fast clock using a browser, only see what the JMRI fast clock is currently set for.

 

I’ll have more details over the weekend.

Randall



On Jun 18, 2020, at 22:48, Andrew Deak <adeakrr@...> wrote:



All

 

I tiring to Jason Http command. I tried this and it will not work? What the format?

 

http://localhost:12080/json/time/rate/4.0/

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Andrew Deak via groups.io
Sent: Thursday, June 18, 2020 10:44 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Paul

 

I want my program to control the clocks and interface into JMRI to update the throttles?

 

I could have JMRI be the master?

 

Thanks

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Paul Bender
Sent: Thursday, June 18, 2020 10:40 PM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Andrew,

 

On Jun 18, 2020, at 8:05 PM, Andrew Deak <adeakrr@...> wrote:

I use a Ubiquiti Wifi module that is just used as access point and setup as gateway.

 

The fastclock do DHCP and I send all info UDP and broadcast all clocks on the system. It should be almost plug and play?

 

For my own use I have interface to NCE Base stations(Networked)

 

I need the best way to interface (protocol) into JMRI and be able update each different command stations (Throttle) thru JMRI?

 

There are multiple ways of doing this. You could, as Randall suggested, use one of the network protocols JMRI supports already  with fast clock support ( the restful Service Randall mentioned, or SRCP, or perhaps some other I am forgetting) or you could add code to JMRI that implements your existing solution and interacts with JMRI’s time base objects.

 

But let me ask this question: what do you want to provide the master clock in the system?  

Do you want JMRI to control the clocks?

Do you want your clock server to control JMRI’s clock?  

 

These are not mutually exclusive options and what you want will provide the guidance we need to give a better answer.

 

Paul

 


Ken Cameron
 

Andrew,

As you are finding out, having your clock system be a slave to JMRI is easy.
To follow and sync with the clock like the throttles do is very easy. But to
setup to be the master, that takes a lot more work to make the right
connection. Consider what is important and go from there. JMRI being the
master is more typical with the other systems that have clocks than JMRI
being the slave. To see some of that you can look into the code for NCE or
Digitrax and how that master/slave setup works out. The easy and quick way
would be adding code to your clock system to take the time from JMRI. The
other is quite doable, but will take more work on both ends.

-Ken Cameron, Member JMRI Dev Team
www.jmri.org
www.fingerlakeslivesteamers.org
www.cnymod.org
www.syracusemodelrr.org


Andrew Deak
 

Ken

If you set the time on NCE or Digitrax system I think JMRI will update JMRI
Clock setting? I could emulate some type of command station?

I been doing remote (internet) Dispatching (old Layout) since 2003. I
written VB6 (C/MRI) code for my Dispatcher display and update my clocks
remotely, If there is a way to be the master then any program could set up
fastclock remotely?

I have a few customers with system (not NCE)and this way I do not have write
code for each different type of DCC system.

I like to have it both way to be Master or Slave if possible?

Just my thoughts

Thanks for the help

Andrew Deak

-----Original Message-----
From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io]
On Behalf Of Ken Cameron
Sent: Friday, June 19, 2020 8:20 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

Andrew,

As you are finding out, having your clock system be a slave to JMRI is easy.
To follow and sync with the clock like the throttles do is very easy. But to
setup to be the master, that takes a lot more work to make the right
connection. Consider what is important and go from there. JMRI being the
master is more typical with the other systems that have clocks than JMRI
being the slave. To see some of that you can look into the code for NCE or
Digitrax and how that master/slave setup works out. The easy and quick way
would be adding code to your clock system to take the time from JMRI. The
other is quite doable, but will take more work on both ends.

-Ken Cameron, Member JMRI Dev Team
www.jmri.org
www.fingerlakeslivesteamers.org
www.cnymod.org
www.syracusemodelrr.org


Bob Jacobsen
 

For background on what JMRI itself can do, see

https://www.jmri.org/help/en/html/tools/fastclock/index.shtml
https://www.jmri.org/help/en/package/jmri/jmrit/simpleclock/SimpleClockFrame.shtml
https://www.jmri.org/help/en/manual/DecoderPro/Main_FastClockSetup.shtml

JMRI knows how to connect to (some) external clocks.

On how three hardware clocks are handled:
https://www.jmri.org/help/en/html/tools/fastclock/LocoNetClock.shtml
https://www.jmri.org/help/en/html/hardware/can/cbus/CbusFastClock.shtml
https://www.jmri.org/help/en/package/jmri/jmrix/nce/clockmon/ClockMonFrame.shtml

One basic question is who provides the timebase (the thing that knows what time it is and tells everybody else). Is that JMRI, or is that an external device/system?

If it’s JMRI, JMRI will update _all_ the attached hardware clocks. If you have LocoNet and NCE attached to JMRI and JMRI has the timebase, it’ll update both sets of throttles.

If an external hardware provides the timebase, that will (occasionally) update JMRI, and JMRI will update both it’s internal time displays and all the _other_ attached devices. If you have LocoNet and NCE attached and NCE has the timebase, NCE will update JMRI, which will update LocoNet.


Bob

On Jun 19, 2020, at 9:25 AM, Andrew Deak <adeakrr@...> wrote:

Ken

If you set the time on NCE or Digitrax system I think JMRI will update JMRI
Clock setting? I could emulate some type of command station?

I been doing remote (internet) Dispatching (old Layout) since 2003. I
written VB6 (C/MRI) code for my Dispatcher display and update my clocks
remotely, If there is a way to be the master then any program could set up
fastclock remotely?

I have a few customers with system (not NCE)and this way I do not have write
code for each different type of DCC system.

I like to have it both way to be Master or Slave if possible?

Just my thoughts

Thanks for the help

Andrew Deak

-----Original Message-----
From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io]
On Behalf Of Ken Cameron
Sent: Friday, June 19, 2020 8:20 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

Andrew,

As you are finding out, having your clock system be a slave to JMRI is easy.
To follow and sync with the clock like the throttles do is very easy. But to
setup to be the master, that takes a lot more work to make the right
connection. Consider what is important and go from there. JMRI being the
master is more typical with the other systems that have clocks than JMRI
being the slave. To see some of that you can look into the code for NCE or
Digitrax and how that master/slave setup works out. The easy and quick way
would be adding code to your clock system to take the time from JMRI. The
other is quite doable, but will take more work on both ends.

-Ken Cameron, Member JMRI Dev Team
www.jmri.org
www.fingerlakeslivesteamers.org
www.cnymod.org
www.syracusemodelrr.org








--
Bob Jacobsen
@BobJacobsen


Randall Wood <rhwood@...>
 

Using the JMRI Web Server and “curl” as the client*, you can get the current fast clock time and settings using:

curl http://192.168.1.32:12080/json/time/time (replace 192.168.1.32 with the IP address of the JMRI server)**

The output will be something similar to:

{"type":"time","data":{"time":"2020-06-20T12:21:12.420+0000","rate":60.0,"state":2}}

where the “data” block is of interest. It contains three pieces of data:

  • time: the current fast clock time as an ISO 8601 formatted date (always in the UTC timezone)
  • rate: the rate (JMRI limits the rate to a value between 1.0 to 100.0 inclusive)
  • state: the state (0 == unknown, 2 == running, 4 == stopped)

To set the JMRI fast clock using the Web Server and curl, you can do the following:

curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.32:12080/json/time/time

If there is a data state you do not wish to change, exclude it (so to set just the time, you would use send the JSON object {"type":"time","data":{"time":"2020-06-20T12:00”}})

The JMRI web server requires that the time be a date and time separated by a T. The example has the minimum amount of time data required.

If you choose to use the JMRI web server to set the JMRI fast clock, note that you must include a Content-Type: application/json HTTP header in your message, of the JMRI web server will silently ignore it.

If you are implementing your clock as a slave to JMRI, you find that using a WebSocket to ws://192.168.1.32:12080/json and then requesting the time with a JSON message {"type":"time","data":{"state":0}} will be preferable to constantly making HTTP requests to see how the time changed. You can see this by opening http://192.168.1.32:12080/json in a web browser and typing the above message into the JSON protocol command space and hitting Send.

*: MacOS and many Linux variants include curl by default. If you are using Linux, try installing from the vendor’s package repo. Otherwise, you should be able to find a version for your OS at https://curl.haxx.se/download.html

**: If you do not use the second /time in the URL, the result is wrapped in a JSON array — in theory JMRI can support multiple different fast clocks, and the protocol would allow that, but the plumbing is not yet there.


Andrew Deak
 

Randall

 

 

I getting errors when tiring to set the clock using curl. The internal clock is not being updated. Am I doing something wrong?

 

 

 

Microsoft Windows [Version 10.0.18363.900]

(c) 2019 Microsoft Corporation. All rights reserved.

 

C:\Users\Andrew>curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.235:12080/json/time/time

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Error 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</title>

</head>

<body><h2>HTTP ERROR 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</h2>

<table>

<tr><th>URI:</th><td>/json/time/time</td></tr>

<tr><th>STATUS:</th><td>500</td></tr>

<tr><th>MESSAGE:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

<tr><th>SERVLET:</th><td>jmri.web.servlet.json.JsonServlet-412ebef7</td></tr>

<tr><th>CAUSED BY:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

</table>

<h3>Caused by:</h3><pre>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]

        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1916)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:772)

        at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)

        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2701)

        at jmri.web.servlet.json.JsonServlet.doPost(JsonServlet.java:286)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

        at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:176)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)

        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278)

        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)

        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

        at org.eclipse.jetty.server.Server.handle(Server.java:500)

        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)

        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)

        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)

        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)

        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)

        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)

        at java.lang.Thread.run(Unknown Source)

</pre>

<hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.28.v20200408</a><hr/>

 

</body>

</html>

 

 

Thanks

 

Andrew Deak

 

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 7:11 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Using the JMRI Web Server and “curl” as the client*, you can get the current fast clock time and settings using:

curl http://192.168.1.32:12080/json/time/time (replace 192.168.1.32 with the IP address of the JMRI server)**

The output will be something similar to:

{"type":"time","data":{"time":"2020-06-20T12:21:12.420+0000","rate":60.0,"state":2}}

where the “data” block is of interest. It contains three pieces of data:

  • time: the current fast clock time as an ISO 8601 formatted date (always in the UTC timezone)
  • rate: the rate (JMRI limits the rate to a value between 1.0 to 100.0 inclusive)
  • state: the state (0 == unknown, 2 == running, 4 == stopped)

To set the JMRI fast clock using the Web Server and curl, you can do the following:

curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.32:12080/json/time/time

If there is a data state you do not wish to change, exclude it (so to set just the time, you would use send the JSON object {"type":"time","data":{"time":"2020-06-20T12:00”}})

The JMRI web server requires that the time be a date and time separated by a T. The example has the minimum amount of time data required.

If you choose to use the JMRI web server to set the JMRI fast clock, note that you must include a Content-Type: application/json HTTP header in your message, of the JMRI web server will silently ignore it.

If you are implementing your clock as a slave to JMRI, you find that using a WebSocket to ws://192.168.1.32:12080/json and then requesting the time with a JSON message {"type":"time","data":{"state":0}} will be preferable to constantly making HTTP requests to see how the time changed. You can see this by opening http://192.168.1.32:12080/json in a web browser and typing the above message into the JSON protocol command space and hitting Send.

*: MacOS and many Linux variants include curl by default. If you are using Linux, try installing from the vendor’s package repo. Otherwise, you should be able to find a version for your OS at https://curl.haxx.se/download.html

**: If you do not use the second /time in the URL, the result is wrapped in a JSON array — in theory JMRI can support multiple different fast clocks, and the protocol would allow that, but the plumbing is not yet there.


Randall Wood <rhwood@...>
 

My suspicion if that “smart" quotes may have snuck into the JSON body, since the parser is complaining that the second character in JSON body (a double quotation character). You want to make sure you have straight quotes (also called “dumb” quotes).

Randall

On 20-Jun-2020, at 09:43, Andrew Deak <adeakrr@...> wrote:

Randall
 
 
I getting errors when tiring to set the clock using curl. The internal clock is not being updated. Am I doing something wrong?
 
 
 
Microsoft Windows [Version 10.0.18363.900]
(c) 2019 Microsoft Corporation. All rights reserved.
 
C:\Users\Andrew>curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.235:12080/json/time/time
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)
at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</title>
</head>
<body><h2>HTTP ERROR 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)
at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</h2>
<table>
<tr><th>URI:</th><td>/json/time/time</td></tr>
<tr><th>STATUS:</th><td>500</td></tr>
<tr><th>MESSAGE:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)
at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>
<tr><th>SERVLET:</th><td>jmri.web.servlet.json.JsonServlet-412ebef7</td></tr>
<tr><th>CAUSED BY:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)
at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>
</table>
<h3>Caused by:</h3><pre>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)
at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1916)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:772)
        at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)
        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2701)
        at jmri.web.servlet.json.JsonServlet.doPost(JsonServlet.java:286)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:176)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.Server.handle(Server.java:500)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
        at java.lang.Thread.run(Unknown Source)
</pre>
<hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.28.v20200408</a><hr/>
 
</body>
</html>
 
 
Thanks
 
Andrew Deak
 
 
From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 7:11 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock
 

Using the JMRI Web Server and “curl” as the client*, you can get the current fast clock time and settings using:

curl http://192.168.1.32:12080/json/time/time (replace 192.168.1.32 with the IP address of the JMRI server)**

The output will be something similar to:

{"type":"time","data":{"time":"2020-06-20T12:21:12.420+0000","rate":60.0,"state":2}}

where the “data” block is of interest. It contains three pieces of data:

  • time: the current fast clock time as an ISO 8601 formatted date (always in the UTC timezone)
  • rate: the rate (JMRI limits the rate to a value between 1.0 to 100.0 inclusive)
  • state: the state (0 == unknown, 2 == running, 4 == stopped)

To set the JMRI fast clock using the Web Server and curl, you can do the following:

curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.32:12080/json/time/time

If there is a data state you do not wish to change, exclude it (so to set just the time, you would use send the JSON object {"type":"time","data":{"time":"2020-06-20T12:00”}})

The JMRI web server requires that the time be a date and time separated by a T. The example has the minimum amount of time data required.

If you choose to use the JMRI web server to set the JMRI fast clock, note that you must include a Content-Type: application/json HTTP header in your message, of the JMRI web server will silently ignore it.

If you are implementing your clock as a slave to JMRI, you find that using a WebSocket to ws://192.168.1.32:12080/jsonand then requesting the time with a JSON message {"type":"time","data":{"state":0}} will be preferable to constantly making HTTP requests to see how the time changed. You can see this by opening http://192.168.1.32:12080/json in a web browser and typing the above message into the JSON protocol command space and hitting Send.

*: MacOS and many Linux variants include curl by default. If you are using Linux, try installing from the vendor’s package repo. Otherwise, you should be able to find a version for your OS at https://curl.haxx.se/download.html

**: If you do not use the second /time in the URL, the result is wrapped in a JSON array — in theory JMRI can support multiple different fast clocks, and the protocol would allow that, but the plumbing is not yet there.



Andrew Deak
 

Randall

 

I cut and paste into command prompt. I then I edited the IP address. Still

get and error?

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 9:54 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

My suspicion if that “smart" quotes may have snuck into the JSON body, since the parser is complaining that the second character in JSON body (a double quotation character). You want to make sure you have straight quotes (also called “dumb” quotes).

 

Randall



On 20-Jun-2020, at 09:43, Andrew Deak <adeakrr@...> wrote:

 

Randall

 

 

I getting errors when tiring to set the clock using curl. The internal clock is not being updated. Am I doing something wrong?

 

 

 

Microsoft Windows [Version 10.0.18363.900]

(c) 2019 Microsoft Corporation. All rights reserved.

 

C:\Users\Andrew>curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.235:12080/json/time/time

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Error 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</title>

</head>

<body><h2>HTTP ERROR 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</h2>

<table>

<tr><th>URI:</th><td>/json/time/time</td></tr>

<tr><th>STATUS:</th><td>500</td></tr>

<tr><th>MESSAGE:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

<tr><th>SERVLET:</th><td>jmri.web.servlet.json.JsonServlet-412ebef7</td></tr>

<tr><th>CAUSED BY:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

</table>

<h3>Caused by:</h3><pre>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]

        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1916)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:772)

        at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)

        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2701)

        at jmri.web.servlet.json.JsonServlet.doPost(JsonServlet.java:286)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

        at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:176)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)

        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278)

        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)

        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

        at org.eclipse.jetty.server.Server.handle(Server.java:500)

        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)

        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)

        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)

        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)

        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)

        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)

        at java.lang.Thread.run(Unknown Source)

</pre>

<hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.28.v20200408</a><hr/>

 

</body>

</html>

 

 

Thanks

 

Andrew Deak

 

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 7:11 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Using the JMRI Web Server and “curl” as the client*, you can get the current fast clock time and settings using:

curl http://192.168.1.32:12080/json/time/time (replace 192.168.1.32 with the IP address of the JMRI server)**

The output will be something similar to:

{"type":"time","data":{"time":"2020-06-20T12:21:12.420+0000","rate":60.0,"state":2}}

where the “data” block is of interest. It contains three pieces of data:

  • time: the current fast clock time as an ISO 8601 formatted date (always in the UTC timezone)
  • rate: the rate (JMRI limits the rate to a value between 1.0 to 100.0 inclusive)
  • state: the state (0 == unknown, 2 == running, 4 == stopped)

To set the JMRI fast clock using the Web Server and curl, you can do the following:

curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.32:12080/json/time/time

If there is a data state you do not wish to change, exclude it (so to set just the time, you would use send the JSON object {"type":"time","data":{"time":"2020-06-20T12:00”}})

The JMRI web server requires that the time be a date and time separated by a T. The example has the minimum amount of time data required.

If you choose to use the JMRI web server to set the JMRI fast clock, note that you must include a Content-Type: application/json HTTP header in your message, of the JMRI web server will silently ignore it.

If you are implementing your clock as a slave to JMRI, you find that using a WebSocket to ws://192.168.1.32:12080/jsonand then requesting the time with a JSON message {"type":"time","data":{"state":0}} will be preferable to constantly making HTTP requests to see how the time changed. You can see this by opening http://192.168.1.32:12080/json in a web browser and typing the above message into the JSON protocol command space and hitting Send.

*: MacOS and many Linux variants include curl by default. If you are using Linux, try installing from the vendor’s package repo. Otherwise, you should be able to find a version for your OS at https://curl.haxx.se/download.html

**: If you do not use the second /time in the URL, the result is wrapped in a JSON array — in theory JMRI can support multiple different fast clocks, and the protocol would allow that, but the plumbing is not yet there.

 


Randall Wood <rhwood@...>
 

It is likely that the browser “corrected” the dumb quotes to smart quotes either when I cut and pasted them into the original message or when you cut and pasted them from the message. Sometimes modern OSes are just too smart for their own good.

Randall

On Jun 20, 2020, at 10:43, Andrew Deak <adeakrr@...> wrote:



Randall

 

I cut and paste into command prompt. I then I edited the IP address. Still

get and error?

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 9:54 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

My suspicion if that “smart" quotes may have snuck into the JSON body, since the parser is complaining that the second character in JSON body (a double quotation character). You want to make sure you have straight quotes (also called “dumb” quotes).

 

Randall



On 20-Jun-2020, at 09:43, Andrew Deak <adeakrr@...> wrote:

 

Randall

 

 

I getting errors when tiring to set the clock using curl. The internal clock is not being updated. Am I doing something wrong?

 

 

 

Microsoft Windows [Version 10.0.18363.900]

(c) 2019 Microsoft Corporation. All rights reserved.

 

C:\Users\Andrew>curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.235:12080/json/time/time

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Error 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</title>

</head>

<body><h2>HTTP ERROR 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</h2>

<table>

<tr><th>URI:</th><td>/json/time/time</td></tr>

<tr><th>STATUS:</th><td>500</td></tr>

<tr><th>MESSAGE:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

<tr><th>SERVLET:</th><td>jmri.web.servlet.json.JsonServlet-412ebef7</td></tr>

<tr><th>CAUSED BY:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

</table>

<h3>Caused by:</h3><pre>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]

        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1916)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:772)

        at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)

        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2701)

        at jmri.web.servlet.json.JsonServlet.doPost(JsonServlet.java:286)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

        at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:176)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)

        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278)

        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)

        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

        at org.eclipse.jetty.server.Server.handle(Server.java:500)

        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)

        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)

        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)

        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)

        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)

        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)

        at java.lang.Thread.run(Unknown Source)

</pre>

<hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.28.v20200408</a><hr/>

 

</body>

</html>

 

 

Thanks

 

Andrew Deak

 

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 7:11 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Using the JMRI Web Server and “curl” as the client*, you can get the current fast clock time and settings using:

curl http://192.168.1.32:12080/json/time/time (replace 192.168.1.32 with the IP address of the JMRI server)**

The output will be something similar to:

{"type":"time","data":{"time":"2020-06-20T12:21:12.420+0000","rate":60.0,"state":2}}

where the “data” block is of interest. It contains three pieces of data:

  • time: the current fast clock time as an ISO 8601 formatted date (always in the UTC timezone)
  • rate: the rate (JMRI limits the rate to a value between 1.0 to 100.0 inclusive)
  • state: the state (0 == unknown, 2 == running, 4 == stopped)

To set the JMRI fast clock using the Web Server and curl, you can do the following:

curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.32:12080/json/time/time

If there is a data state you do not wish to change, exclude it (so to set just the time, you would use send the JSON object {"type":"time","data":{"time":"2020-06-20T12:00”}})

The JMRI web server requires that the time be a date and time separated by a T. The example has the minimum amount of time data required.

If you choose to use the JMRI web server to set the JMRI fast clock, note that you must include a Content-Type: application/json HTTP header in your message, of the JMRI web server will silently ignore it.

If you are implementing your clock as a slave to JMRI, you find that using a WebSocket to ws://192.168.1.32:12080/jsonand then requesting the time with a JSON message {"type":"time","data":{"state":0}} will be preferable to constantly making HTTP requests to see how the time changed. You can see this by opening http://192.168.1.32:12080/json in a web browser and typing the above message into the JSON protocol command space and hitting Send.

*: MacOS and many Linux variants include curl by default. If you are using Linux, try installing from the vendor’s package repo. Otherwise, you should be able to find a version for your OS at https://curl.haxx.se/download.html

**: If you do not use the second /time in the URL, the result is wrapped in a JSON array — in theory JMRI can support multiple different fast clocks, and the protocol would allow that, but the plumbing is not yet there.

 


Andrew Deak
 

Randall

 

 

I like to see what testing conditions you are using to make it work? I using windows 10 and Chrome and IE browser. Should this work in  command prompt also?

 

Thanks

 

Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 10:51 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

It is likely that the browser “corrected” the dumb quotes to smart quotes either when I cut and pasted them into the original message or when you cut and pasted them from the message. Sometimes modern OSes are just too smart for their own good.

Randall



On Jun 20, 2020, at 10:43, Andrew Deak <adeakrr@...> wrote:



Randall

 

I cut and paste into command prompt. I then I edited the IP address. Still

get and error?


Andrew Deak

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 9:54 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

My suspicion if that “smart" quotes may have snuck into the JSON body, since the parser is complaining that the second character in JSON body (a double quotation character). You want to make sure you have straight quotes (also called “dumb” quotes).

 

Randall




On 20-Jun-2020, at 09:43, Andrew Deak <adeakrr@...> wrote:

 

Randall

 

 

I getting errors when tiring to set the clock using curl. The internal clock is not being updated. Am I doing something wrong?

 

 

 

Microsoft Windows [Version 10.0.18363.900]

(c) 2019 Microsoft Corporation. All rights reserved.

 

C:\Users\Andrew>curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.235:12080/json/time/time

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Error 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</title>

</head>

<body><h2>HTTP ERROR 500 com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</h2>

<table>

<tr><th>URI:</th><td>/json/time/time</td></tr>

<tr><th>STATUS:</th><td>500</td></tr>

<tr><th>MESSAGE:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

<tr><th>SERVLET:</th><td>jmri.web.servlet.json.JsonServlet-412ebef7</td></tr>

<tr><th>CAUSED BY:</th><td>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]</td></tr>

</table>

<h3>Caused by:</h3><pre>com.fasterxml.jackson.core.JsonParseException: Unexpected character (&apos;&apos;&apos; (code 39)): expected a valid value (JSON String, Number, Array, Object or token &apos;null&apos;, &apos;true&apos; or &apos;false&apos;)

at [Source: (org.eclipse.jetty.server.Request$1); line: 1, column: 2]

        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)

        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1916)

        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:772)

        at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)

        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2701)

        at jmri.web.servlet.json.JsonServlet.doPost(JsonServlet.java:286)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

        at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:176)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)

        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)

        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278)

        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)

        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

        at org.eclipse.jetty.server.Server.handle(Server.java:500)

        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)

        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)

        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)

        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)

        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)

        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)

        at java.lang.Thread.run(Unknown Source)

</pre>

<hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.28.v20200408</a><hr/>

 

</body>

</html>

 

 

Thanks

 

Andrew Deak

 

 

From: jmri@jmri-developers.groups.io [mailto:jmri@jmri-developers.groups.io] On Behalf Of Randall Wood via groups.io
Sent: Saturday, June 20, 2020 7:11 AM
To: jmri@jmri-developers.groups.io
Subject: Re: [jmri-developers] Wifi FastClock

 

Using the JMRI Web Server and “curl” as the client*, you can get the current fast clock time and settings using:

curl http://192.168.1.32:12080/json/time/time (replace 192.168.1.32 with the IP address of the JMRI server)**

The output will be something similar to:

{"type":"time","data":{"time":"2020-06-20T12:21:12.420+0000","rate":60.0,"state":2}}

where the “data” block is of interest. It contains three pieces of data:

  • time: the current fast clock time as an ISO 8601 formatted date (always in the UTC timezone)
  • rate: the rate (JMRI limits the rate to a value between 1.0 to 100.0 inclusive)
  • state: the state (0 == unknown, 2 == running, 4 == stopped)

To set the JMRI fast clock using the Web Server and curl, you can do the following:

curl -H "Content-Type: application/json" -d '{"type":"time","data":{"time":"2020-06-20T12:00","rate":60.0,"state":2}}' http://192.168.1.32:12080/json/time/time

If there is a data state you do not wish to change, exclude it (so to set just the time, you would use send the JSON object {"type":"time","data":{"time":"2020-06-20T12:00”}})

The JMRI web server requires that the time be a date and time separated by a T. The example has the minimum amount of time data required.

If you choose to use the JMRI web server to set the JMRI fast clock, note that you must include a Content-Type: application/json HTTP header in your message, of the JMRI web server will silently ignore it.

If you are implementing your clock as a slave to JMRI, you find that using a WebSocket to ws://192.168.1.32:12080/jsonand then requesting the time with a JSON message {"type":"time","data":{"state":0}} will be preferable to constantly making HTTP requests to see how the time changed. You can see this by opening http://192.168.1.32:12080/json in a web browser and typing the above message into the JSON protocol command space and hitting Send.

*: MacOS and many Linux variants include curl by default. If you are using Linux, try installing from the vendor’s package repo. Otherwise, you should be able to find a version for your OS at https://curl.haxx.se/download.html

**: If you do not use the second /time in the URL, the result is wrapped in a JSON array — in theory JMRI can support multiple different fast clocks, and the protocol would allow that, but the plumbing is not yet there.