This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create action from switch attached to GPIO
#1
How do I create an action from a switch attached to a GPIO 

I have created the switch under GPIO as an input, pull down

the momentary contact switches are connected between a GPIO and ground. I have two. 

One I eventually want to use to generate a MOB alarm and create a waypoint in OCPN.. 

The other I want to use to cancel alarms by clearing all messages and setting another GPIO to low. 

Let's say I have a temperature sensor that triggers an alarm above a certain temperature. I have actions configured to display a message and set a GPIO output high which operates a relay that lights an illuminated push button switch. 

The idea is that you press the illuminated button to clear the alarm from the display and turn off the light. 

How do I set up an action that detects that the push button has been pushed? 

Chris
  Reply
#2
If you want to trigger when a pin is connected to ground then the gpio pin needs to be configured as pull up, otherwise it's always connected to ground internally. In this example there are 3 pins being used, when pin 26 is connected to ground it turns the LED on pin 16 on, then if pin 19 is connected to ground it turns the LED off again.
On openplotter V0.11.7 alpha.

[Image: jaxYtit.png]
[Image: 9CBBid0.png]
[Image: u0aebhZ.png]

Creating a waypoint in opencpn doesn't look so easy though:
From
https://opencpn.org/wiki/dokuwiki/doku.p..._sentences


Quote:xxWPL - Waypoint Location Used to send routes and waypoints up to a GPS receiver. OpenCPN does not process these sentences as input.

Edit: Though digging deeper...
https://opencpn.org/flyspray/index.php?d...sk_id=1595

Quote:I've just recently realised that, in theory, OCPN should read-in a WPL sentance in the context of APRS, and generate a specific AIS target. If this is the case, the contextual menu (right click on the AIS target/target query) should offer the possibility of creating a waypoint.
Actually creating the nmea sentence might be a job better suited to node-red - quite easy to get at the signalk data, or anyone know how to do that as bash?
  Reply
#3
Thanks PaddyB. I had my nomenclature logic upside down with how I thought the input logic was labeled. Now that I have stage one working I can work on sending a sentence to OCPN... or at at least recording marks to a log file that can be converted to a GPX file for later import which may be a reachable intermediate step.

A couple more thoughts.

OCPN can generate MOB markers in a couple of ways. One is with keyboard input CTRL+SPACE another is with an AIS SART input sentence over NMEA which it should be possible to simulate.

Can OP be used, at the moment, to simulate a keyboard input with OCPN as the receiving app?
  Reply
#4
I thought a tool like "xdotool" might work (ctrl+space is the keyboard shortcut to drop a MOB marker) but it doesn't seem to do anything on the Pi.. ??

I was thinking to use an action to issue a command like
Code:
xdotool search --name "OpenCPN 4.6.1" key ctrl+space

which runs without error but doesn't do anything either; anybody any ideas on this ? 

P.S. I haven't tried running this as an action yet. I've only been experimenting in a terminal
  Reply
#5
(05-20-2017, 09:52 AM)Littlechay Wrote: I thought a tool like "xdotool" might work (ctrl+space is the keyboard shortcut to drop a MOB marker) but it doesn't seem to do anything on the Pi.. ??

I was thinking to use an action to issue a command like
Code:
xdotool search --name "OpenCPN 4.6.1" key ctrl+space

which runs without error but doesn't do anything either; anybody any ideas on this ? 

P.S. I haven't tried running this as an action yet. I've only been experimenting in a terminal

 xdotool search "OpenCPN 4.6.1" windowactivate --sync key --clearmodifiers l

That works to turn on and off the light in opencpn so you must be close, can't get it working with cntrl  space though. Good find!
  Reply
#6
(05-20-2017, 10:35 AM)PaddyB Wrote:
(05-20-2017, 09:52 AM)Littlechay Wrote: I thought a tool like "xdotool" might work (ctrl+space is the keyboard shortcut to drop a MOB marker) but it doesn't seem to do anything on the Pi.. ??

I was thinking to use an action to issue a command like
Code:
xdotool search --name "OpenCPN 4.6.1" key ctrl+space

which runs without error but doesn't do anything either; anybody any ideas on this ? 

P.S. I haven't tried running this as an action yet. I've only been experimenting in a terminal

 xdotool search "OpenCPN 4.6.1" windowactivate --sync key --clearmodifiers l

That works to turn on and off the light in opencpn so you must be close, can't get it working with cntrl  space though. Good find!

Thanks.. I'll go and ask in the OCPN forum
  Reply
#7
(05-20-2017, 06:39 PM)Littlechay Wrote:
(05-20-2017, 10:35 AM)PaddyB Wrote:
(05-20-2017, 09:52 AM)Littlechay Wrote: I thought a tool like "xdotool" might work (ctrl+space is the keyboard shortcut to drop a MOB marker) but it doesn't seem to do anything on the Pi.. ??

I was thinking to use an action to issue a command like
Code:
xdotool search --name "OpenCPN 4.6.1" key ctrl+space

which runs without error but doesn't do anything either; anybody any ideas on this ? 

P.S. I haven't tried running this as an action yet. I've only been experimenting in a terminal

 xdotool search "OpenCPN 4.6.1" windowactivate --sync key --clearmodifiers l

That works to turn on and off the light in opencpn so you must be close, can't get it working with cntrl  space though. Good find!

Thanks.. I'll go and ask in the OCPN forum

Doing some more tests it seems that any single key command works, such as "o" changing chart outlines "m" turning on the measure tool etc. If I send ctrl+o the chart outlines are toggled so it seems that OCPN is not seeing the ctrl+ part ..... hmmmmmm
  Reply
#8
OK some some experimentation and I have made one step forward and one back !

I can drop the MOB marker in OCPN from the command line with the XVKBD (a virtual keyboard) using the commad


Code:
xvkbd -window "OpenCPN 4.6.1" -text " \C "


Note: there is space after the C

Works every time from a terminal.

When I enter it as an action in OpenPlotter it does nothing. Or rather the only effect that it has is duplicate another action that I had tied to the MOB button condition (it is just a message that gives the lat and lon that I had in there for testing).

I have tried deleting the other actions so that the xvkbd command is the only one associated with the MOB button condition - nothing happens

Running OpenPlotter from the command line in a terminal produces no errors.

Any ideas anybody? Frustrating this, so close but no bananas!
  Reply
#9
(05-23-2017, 10:13 PM)Littlechay Wrote: Any ideas anybody? Frustrating this, so close but no bananas!

Seems to work OK if you create a little bash script then run that from an openplotter command:

The screen grabs are with an action based on engine.temp greater than 0 but I've just tested it triggered by a gpio pin pulled to ground which seems to work fine as well. 

Good idea!!! 

[Image: 3tKs1Si.png]

[Image: oFephgi.png]
  Reply
#10
Thanks good idea to put it in a script; which I had thought about but not got around to.

I have done it now. Works every time from the command line but nothing happens when triggered from an action.

Permissions are set on the script. I put it on the same path as you have done.. nothing.

The trigger is working OK just nothing from this action. Anything different from default in your system that may be affecting things?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)