LIRC - How to use as keyboard command? - lirc

i have a question about LIRC in Debian. I searched now for some days and could not find any solution for my problem.
Is it possible to use an IR-Remote to send keyboard commads?
I will explain:
I use the "read" function in a shell script. So i.e. i press the "T" key something happens. Now i want to send via LIRC the same "T" so that the shell script is working with the remote, too.
The other way is, not in a shell script but at my sources of the C-program.
Here i use a code like this:
case 't': {
so if button "t" at keyboard is pressed something happens.
I hope someone can help me to use LIRC because i canĀ“t understand the descriptions at the LIRC webpage. Every example is based on programs they allready support lirc commands.
Thank you very much
Regards Thomas

Assuming that you know how to use lircd, irexec and configure it through /etc/lircd.conf and /etc/lircrc, you could have something like this in your /etc/lircrc:
begin
remote = name-of-your-remote
prog = irexec
button = BTN_1
config = echo T >/dev/xxx
end
BTN_1 should be configured in your /etc/lircd.conf to match 'T' key on your remote IR keyboard.
xxx is the TTY device that is used by your active shell, e.g. I've tried it with /dev/pts/0
If you need it to be accessible from your custom program's stdin, you can use the following config:
begin
remote = name-of-your-remote
prog = irexec
button = BTN_1
config = echo T | your-prog
end

I found that the lircd-uinput.service is used to send keyboard events to /dev/uinput, basically to the console. This is a handy service if you want to use a remote to send a keyboard key to a custom menu or program running on the console. The problem with the service, is that it keeps repeating the key until it receives a release code.
The 'repeat' behavior is by design, I guess because most well-written applications probably send something like a KEY_DOWN when a key is pressed, then a KEY_UP when it is released. But my simple application is not smart enough to send a release code, so I found an easy solution to the key repeat problem, and can use the service to fake a keyboard using an IR remote.
To make the lircd-uinput.service register the key-release event automatically, and stop repeating the key, edit the service and add the --add-release-events option.
sudo nano /lib/systemd/system/lircd-uinput.service
####find this line####
ExecStart=/usr/sbin/lircd-uinput
####change to#########
ExecStart=/usr/sbin/lircd-uinput --add-release-events
Restart the services and make sure they're active.
sudo systemctl force-reload lircd
sudo systemctl force-reload lircd-uinput
sudo systemctl status lircd
sudo systemctl status lircd-uinput
#I had to start lircd-uinput, since force-reload didn't:
sudo systemctl start lircd-uinput
Now the service only enters one keypress for each remote button press, and automatically sends the KEY_UP command. If you know how to send the KEY_UP commands in your application, that might work better than this solution.
To figure out the key commands that correspond to keyboard keys, you can list all possible keyboard events supported by the kernel by running:
irrecord -l
For example, if you want your remote to press the down arrow key on your console, the corresponding remote key is 'KEY_DOWN'. Then your remote file (/etc/lirc/lircd.conf.d/myremote.conf) would contain that key name.
begin remote
name myremote
#<sniped...remote stuff here...>
begin codes
# <sniped other codes>
KEY_DOWN 0x00FF
# <sniped other codes>
end codes
end remote
Now that we've stopped the key repeating, this is a really useful service. It is much more responsive than using irexec to fake a keyboard key to the console, and you don't need any configuration in irexec.lircrc to send keystrokes to your console. And you can still use irexec for your other, non-keyboard related commands.

Related

Can PM2 take an action upon a process being marked "Errored"

PM2 will mark a process status "Errored" if it restarts more than "max_restarts" where each restart lasts less than "min_uptime". Perhaps it happens in other circumstances as well.
I'd like to take an action in the event that such a string of fatal errors occur. In my case, I'd like to reboot the whole machine since it means something horrible has occurred. Is this possible?
Note: I now see that it's possible to do this when PM2 is being used programmatically (see answer below). Is there a way to do it automatically through the CLI instead? Something similar to a githook that runs automatically upon the "errored" status being raised.
If PM2 is being used programmatically, this function can be used:
pm2.describe(process,errback)
It returns 'processDescription', which includes 'pm2_env', which includes 'status', which would show 'errored'.
This may answer the question for someone else, but it does not answer the question for me, as I would like to use PM2 via CLI call, and not from within another node script.
The question is quite old, but I had the same problem and nowadays, there is a CLI solution:
You can use pm2 jlist to get the current process list as JSON and parse it for example with jq. To search for all processes managed by pm2 in status "errored", you could call something like:
pm2 jlist | jq '.[] | {"name": .name, "status": .pm2_env.status} | select(.status=="errored")'

How to ping from Zabbix agent?

Is it possible to ping from Zabbix agent and pass that data into Zabbix server? I would like to be able to get response time from the agent.
I read that it is possible by using fping, would be great if someone could guide me to the correct path.
Thank you,
Rijath Mohammed
While that is not currently available out of the box, you can implement such a functionality using a feature called "user parameters". This forum thread has a simple example:
UserParameter=myping[*],/etc/zabbix/fping -q $1;echo $?
Although for you the path to fping is likely to be /usr/sbin/fping or /usr/bin/fping.
You can read more about user parameters in the official manual: https://www.zabbix.com/documentation/3.0/manual/config/items/userparameters .
While I haven't ever configured that, it would be similar on Windows - see this forum thread for some inspiration.
And if you would like to see this feature implemented out of the box, make sure to vote on this feature request.
Got it working using the below powershell script, :)
$Test = test-connection google.com -count 1
$Test.responsetime
This will just return the response time for Google.com and that value is passed to Zabbix using the below user parameter:
UnsafeUserParameters=1
UserParameter=ping.google,C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\zabbix\pinggoogle.ps1
I am calling this parameter from Zabbix using the key "ping.google"

Fiware CEP server stops responding

In developing in Fi-Cloud's CEP I've been having an issue that has been happening repeatedly. As I'm trying to develop a definition to perform a task, CEP's server and Authoring Tool stop responding, although ssh is still responsive.
This issue happens as I develop. I'm using the AuthoringTool to alter the definition bit by bit and then I re-upload it to the server through the authoring tool's export feature.
To reinitiate the proton with the new definition each time I alter it, I use Google's Postman with this single operation:
-PUT (url:http://{ip}:8080/ProtonOnWebServerAdmin/resources/instances/ProtonOnWebServer)
header: 'Content-Type' : 'application/json'; body : {"action": "ChangeDefinitions","definitions-url" : "/ProtonOnWebServerAdmin/resources/definitions/Definition_Name"}
At the same time, I'm logged in with three ssh intances, one to monitor the files being created on /opt/tomcat10/sample/ and other things, and the other two to 'tail -f ' log files the definition writes to, as events are processed: one log for events recieved and another log for events detected by the EPAgent.
I'm iterating through these procedures over and over as I'm developing and eventualy CEP server and the Authoring Tool stop responding.
By "tailing" tomcat's log file (# tail -f /opt/tomcat10/logs/catalina.out) I can see that, when under these circumstances, if I attemp a:
-GET (url: http://{ip}:8080/ProtonOnWebServerAdmin/resources/instances/ProtonOnWebServer)
I get no response back and tomcat logs the following response:
11452100 [http-bio-8080-exec-167] ERROR org.apache.wink.server.internal.RequestProcessor - An unhandled exception occurred which will be propagated to the container.
java.lang.OutOfMemoryError: PermGen space
Exception in thread "http-bio-8080-exec-167" java.lang.OutOfMemoryError: PermGen space
Ssh is still responsive and I can look at tomcat's log this way.
To get over this and continue, I exit ssh connections and restart CEP's instance in the Fi-Cloud.
Is the procedure I'm using to re-upload and re-run the definition inapropriate? Should I take a different approach to developing?
When you update a definition that the CEP is already working with, and you want the CEP engine to work with the updated definition, you need to:
Export the definition using the authoring tool export (as you did)
Stop the engine run, using REST PUT
PUT //host:8080/ProtonOnWebServerAdmin/resources/instances/ProtonOnWebServer
{"action":"ChangeState","state":"stop"}
Start the engine, using REST PUT
PUT //host:8080/ProtonOnWebServerAdmin/resources/instances/ProtonOnWebServer
{"action":"ChangeState","state":"start"}
You don't need to activate the "ChangeDefinitions" action, since it is the same definition name that the engine is already working with.
Activating "ChangeDefinitions" action, only influences the next run of the CEP, and has no influence on the current run.
This answer your question about how you should update a CEP definition.
Hope it will solve your issue.

Expect: Can I set a permanent pattern - action pair for multiple expect command

I work with an embedded system which I can access through a serial debug port for debugging. I want to use it's cli interface that can be accessed with telnet localhost in debug console (even before the system is fully up) through expect. The problem is, the cli interface kicks me out at random times with Connection closed by foreign host. near startup (this behavior cannot be changed in the system).
This is the background, my question is that is there any method or trick in expect with which I can set a pattern-action pair permanently for all expect command (in some specific scope)? I would like to setup something like this:
expect "Connection closed by foreign host." { error "cli closed" }
And use this in all the expect command in all my tcl proc that handles cli stuff, then I would call my proc with catch from the main program, and could handle the disconnection. If I can't set this pattern-action pair permanently, I have to include this in all my expect command, which would be really tedious (or use some kind of state instead of multiple expect command, which would be even more tedious..)
Any other idea to work around this is welcome too!
There's an expect_before command: The patterns and actions defined in expect_before are "imported" into every subsequest expect command. So, you want:
expect_before "Connection closed by foreign host." { error "cli closed" }

How do BundleActivator, ManagedService, and my application interact on start/stop?

I had a non-OSGi application. To convert it to OSGi, I first bundled it up and gave it a simple BundleActivator. The activator's start() started up a thread of what used to be the main() of my app (and is now a Runnable), and remembered that thread. The activator's stop() interrupted that thread, and waited for it to end (via join()), then returned. This all seemed to be working fine.
As a next step in the OSGiification process, I am now trying to use OSGi configuration management instead of the Properties-based configuration that the application used to use. So I am adding in a ManagedService in addition to the Activator.
But it's no longer clear to me how I am supposed to start and stop my application; examples that I've seen are only serving to confuse me. Specifically, here:
http://felix.apache.org/site/apache-felix-config-admin.html
They no longer seem to do any real starting of the application in BundleActivator.start(). Instead, they just register a ManagedService to receive configuration. So I'm guessing maybe I start up the app's main thread when I receive configuration, in the ManagedService? They don't show it - the ManagedService's updated() just has vague comments saying to "apply configuration from config admin" when it is passed a non-null Dictionary.
So then I look here:
http://blog.osgi.org/2010/06/how-to-use-config-admin.html
In there, it seems like maybe they're doing what I guessed. They seem to have moved the actual app from BundleActivator to ManagedService, and are dealing with starting it when updated() receives non-null configuration, stopping it first if it's already started.
But now what about when the BundleActivator's stop() gets called?
Back on the first example page that I mentioned above, they unregister the ManagedService. On the second example page, they don't show what they do.
So I'm guessing maybe unregistering the ManagedService will cause null configuration to be sent to ManagedService.updated(), at which point I can interrupte the app thread, wait for it to end, and then return?
I suspect that I'm thoroughly incorrect, but I don't know what the "real" way to do this is. Thanks in advance for any help.
BundleActivator (BA) and ManagedService (MS) are callbacks to your bundle. BundleActivator is for the active state of your bundle. BA.start is when you bundle is being started and BA.stop is when it is being stopped. MS is called to provide your bundle a configuration, if there is one, or notify you there is no configuration.
So in BA.start, you register your MS service and return. When MS is called (on some other thread), you will either receive your configuration or be told there is no configuration and you can act accordingly (start app, etc.)
Your MS can also be called at anytime to advice of the modification or deletion of your configuration and you should act accordingly (i.e. adjust your app behavior).
When you are called at BA.stop, you need to stop your app. You can unregister the MS or let the framework do it for you as part of normal bundle stop processing.