Controlling a servo at Raspberry Pi with Springboot and ServoBlaster - spring-boot

I am trying to control a servo motor from a web interface. I am using SpringBoot 2.0, ServoBlaster and pi4j.
In order to start the application I am running as root ./gradlew bootrun --no-daemon. It has to be root in order to handle the GPIOs and I don't have any security worries about the device.
In simplified (a class with just the main function) Java/Kotlin I achieved to control the servo by any of the following ways:
RPIServoBlasterProvider
val servoProvider = RPIServoBlasterProvider()
val servo0 = servoProvider.getServoDriver(servoProvider.definedServoPins[5])
println("Go to 150") //middle
servo0.servoPulseWidth = 150
println("Went to ${servo0.servoPulseWidth}")
Thread.sleep(1550)
Write to /dev/servoblaster
val out = PrintWriter(FileOutputStream("/dev/servoblaster"), true)
println("Go to 65 again")
out.println("5=65")
out.flush()
out.close
Call a secondary script which writes to /dev/servoblaster
val servoId = 5
val script = "/home/pi/ServoHardwareSteering.sh"
val cmdMinPosition = "$script $servoId 65"
val cmdMidPosition = "$script $servoId 150"
val cmdMaxPosition = "$script $servoId 235"
val runtime = Runtime.getRuntime()
println(cmdMidPosition)
runtime.exec(cmdMidPosition)//.waitFor()
Thread.sleep(1550)
Write the value to a file and have a secondary execute reading this file and applying this value to the servo
I have tried all of the above in Springboot but without success.
So the question is, could somebody tell me how could I:
use the RPIServoBlasterProvider class from Springboot? OR
write to /dev/servoblaster? OR
execute any terminal script? OR
where to save the script in order to be able to call it OR
write to a simple file (ex. afile.txt)? OR
solve the issue in a better way that I did not think about already.
Solutions at any of the above questions could help me solve my problem.
PS: Is there anything wrong with the blockquote for the source code in stackoverflow? I could not format it as a block and I used the line code formatting!

use the RPIServoBlasterProvider class from Springboot? OR
The same you did before - its Java (kotlin is based on) - or just use Kotlin with Spring https://spring.io/guides/tutorials/spring-boot-kotlin/
write to /dev/servoblaster? OR
The same like you did - everything is a file in linux, thus its writing to a ordinary file
execute any terminal script? OR
Runtime.getRuntime.exec - any variant or ProcessBuilder
where to save the script in order to be able to call it OR
Anywhere
write to a simple file (ex. afile.txt)? OR
point 2.
solve the issue in a better way that I did not think about already.
No experience with servo blaster.

The whole problem was with the servod of the ServoBlaster. It was accidentally killed and I had to run it once again!
I followed the No 5 solution.

Related

why scrapy won't load any of my pipelines?

ok, so Im using Scrapy for some basic web scraping and its working fine on scraping part! when get some output using feed export something like -o output.csv wont do anything, it will make an empty file but nothing else.
after a period of confusion I couldn't make it work so i've decided to use a pipeline to write some custom method of exporting. but now the problem is even though the application is working fine... its just not load the pipelines. not any single one of them is not running and there is no error.
this is my settings.py where I put the option to load them:
ITEM_PIPELINES = {
'fbcrawl.pipelines.CsvExporterPipeline': 300
}
and this is my CsvExporterPipeline class inside pipelines.py:
class CsvExporterPipeline(object):
def process_item(self, item, spider):
print('\n' * 2)
print(item)
print('\n' * 2)
return item
and its not gonna run neither of these 3 prints wont run at all.
I want to know how can I have my pipelines loaded and working?
UPDATE: i forgot to mention that im trying to run this code... so the spider is mentioned here:
https://github.com/rugantio/fbcrawl
Are you sure BOT_NAME in settings.py is set at fbcrawl ?
And what is the code of your spider ?

osquery extension in Ruby - create new table

I'm trying to implement an extension for osquery in Ruby.
I found some libs and examples doing the same in Java, Node and Python, but nothing helpful implemented in Ruby language.
According to this documention, it's possible generating the code using Thrift: https://osquery.readthedocs.io/en/stable/development/osquery-sdk/#thrift-api
The steps I did, so far:
Generated the code using thrift -r --gen rb osquery.thrift
Created a class and some code to connect to the server and register the extension
This is the code of the class
# include thrift-generated code
$:.push('./gen-rb')
require 'thrift'
require 'extension_manager'
socket = Thrift::UNIXSocket.new(<path_to_socket>)
transport = Thrift::FramedTransport.new(socket)
protocol = Thrift::BinaryProtocol.new(transport)
client = ExtensionManager::Client.new(protocol)
transport.open()
info = InternalExtensionInfo.new
info.name = "zzz"
info.version = "1.0"
extension = ExtensionManager::RegisterExtension_args.new
extension.info = info
client.registerExtension(extension, {'table' => {'zzz' => [{'name' => 'TEXT'}]}})
To get the <path_to_socket> you can use:
> osqueryi --nodisable_extensions
osquery> select value from osquery_flags where name = 'extensions_socket';
+-----------------------------------+
| value |
+-----------------------------------+
| /Users/USERNAME/.osquery/shell.em |
+-----------------------------------+
When I try to get this table using osqueryi, I don't see the table when I run select * from osquery_registry;.
Have anybody by any chance implemented an osquery extension already? I'm stuck and I don't know how to proceed from here.
I don't think I've seen anyone make a ruby extension, but once you have the thrift side, it should be pretty simple.
As a tool, osquery supports a lot of options. So there's no single way to do this. Generally speaking, extensions run as their own process and the communicate over that thrift socket.
Usually, they're very simple and osquery invokes extensions directly with appropriate command line arguments. This is alluded to in the doc you linked with the example accepting --interval, --socket, and --timeout. If you do this, you'll want to look at osquery's --extensions_autoload and --extensions_require option. (I would recommend this route)
Less common, is to start osquery with a specified socket path using --extensions_socket. And then your extension can use that. This way is more common is the extension cannot be a simple binary, and instead is a large complex system.
I find myself playing around with thrift via ruby. And it seems to work if I used a BufferedTransport:
socket = Thrift::UNIXSocket.new('/tmp/osq.sock')
transport = Thrift::BufferedTransport.new(socket)
protocol = Thrift::BinaryProtocol.new(transport)
client = ExtensionManager::Client.new(protocol)
transport.open()
client.ping()
client.query("select 1")

How to execute UFT scripts through AOM Framework?

I have Five Automated Script and want to execute overnight. Can anyone let me know how to execute it ?
Yes, you can schedule those tasks using task scheduler using Application Object Model(AOM).
There are many ways, one approach you can use am writing below:
Create a vbs file and trigger it using Windows scheduler. You can write code to pick up your execution scripts in UFT. Refer below code for your reference.
Set obj = CreateObject("Quicktest.Application")
'// Set AOM file and test script path
obj.Visible = True
obj.Launch
obj.Options.Run.ImageCaptureForTestResults = "OnError"
obj.Options.Run.RunMode = "Fast"
obj.Options.Run.ViewResults = False
obj.Open path '----"path of your script"
obj.Test.Run qtpResults,True
VarStatus =obj.Test.LastRunResults.Status
obj.Test.Close
Let me know if you need any other help. Happy to help :-)

How do we import the listener events of LibreOffice Writer in Visual Basic 6

How do we import the listener events of LibreOffice writer in Visual Basic 6?
I am trying to create a UNO service to get container listener event like following code,
Dim oListener As Object
oListener = CreateUnoListener("ContListener_",
"com.sun.star.container.XContainerListener")
I am getting an error
Compile error : Sub or Function not defined
Can anyone please help?
As explained here, CreateUnoListener does not work in VB6. So instead, it is necessary to implement the listener interface a different way.
Here is a VBScript example from https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Document_Events.
set xContext = objServiceManager.getPropertyValue( "DefaultContext" )
set xCoreReflection = xContext.getValueByName( "/singletons/com.sun.star.reflection.theCoreReflection" )
set xClass = xCoreReflection.forName( "com.sun.star.document.XEventBroadcaster" )
set xMethod = xClass.getMethod( "addEventListener" )
dim invokeargs(0)
invokeargs(0) = myListener
set value = objServiceManager.Bridge_GetValueObject()
call value.InitInOutParam("[]any", invokeargs)
call xMethod.invoke( objDocument, value )
Define a subroutine called myListener.
It may also help to check out the information at https://www.openoffice.org/udk/common/man/tutorial/office_automation.html.
There is a discussion of someone attempting similar code at https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=14217, although the final solution uses Javascript.
Disclaimer: I do not have any way to test VB6 code, so this information may not be entirely accurate. If you switch to Python or another language commonly used with LibreOffice then I can be of more help.

HP UFT API Test - Saving Response/Checkpoint values

Is there a way to capture and store (or write to a file) the values returned in the Response? (Checkpoint values)
Using HP UFT 11.52
Thanks,
Lynn
I figured it out. In UFT API under Standard Activities, there are File function modules including "Write to File". I added the module to the test, set the path and other properties, passed the variable to the file and it worked! Couldn't be easier.
I mentioned this on my other answer , you can also write it programatically if you have dynamic array response please refer below:
https://stackoverflow.com/a/28012383/3972994
After running a test, in the test folder, you can find a Snapshots/LastIteration directory.
In it you can find the return value for each step saved in a txt file.
Pay attention that if you data drive the step, only the last iteration will be saved to file.
However, in the Test's log (Test dir/Log/vtd_user.log) you can find all the iterations persisted
Thanks,
Yossi
You do not need to use the standard activities if you do this
var iResponse = this.Activity.responsebody;
System.IO.File.WriteLines(#"directorypath&FileName);
the above will write the response to the file and rewrite it for every run

Resources