best way to deploy files to cumulocity devices? - cumulocity

Using the cumulocity java-agent is there a way to upload a file (i.e. zip) to the FILES REPOSITORY, on the Admin page, then either push this file to all my devices or instruct all devices to pull this file?

You can use the software management process (in devicemanagement).
You upload the file to the software management. Afterwards you can use the file from the software plugin. This will create an operation for the device which contains a direct link to the file.
On the device you then just need to call a GET on this link. There is no specific service implemented for that at the moment.
If you are not talking about software but files in general I would recommend a similar process. Send an operatio to the device that contains a download link to the file.

I think SW installer is only half solution as the java-agent may b broken currently (cumulocity-linux-agent-7.29.0). Agent says:
[CumulocityLongPollingTransport-scheduler-3] WARN
c8y.lx.agent.JavaSoftwareDriver - Malformed URL:
common-notification-6.17.0.jar
[CumulocityLongPollingTransport-scheduler-3] WARN
c8y.lx.agent.JavaSoftwareDriver - Malformed URL: commons-io-2.4.jar
[CumulocityLongPollingTransport-scheduler-3] WARN
c8y.lx.agent.JavaSoftwareDriver - Malformed URL:
svenson-1.3.8-6.17.0.jar
The operation actually does not have the full URL only the filename:
{
operations: [
{
...
status: "PENDING",
description: "Update device software.",
c8y_Software: {
rest-representation: "rest-representation-7.29.1.jar",
tinkerforge: "tinkerforge-2.1.2.jar",
...
I could only get the SW installer work with the java agent by hosting the files externally and using such syntax on the admin page:
NAME: tinkerforge-driver
VERSION: http://my_ip/tinkerforge-driver-6.17.0.jar
FILE: http://my_ip/tinkerforge-driver-6.17.0.jar

Related

Workstation hosted vscode extension not processing message from remote hosted extension

QV https://github.com/microsoft/vscode-remote-release/issues/7736
I have two extensions. One of them is of uiKind workspace and may run locally or remotely depending on the workspace, and the other is of uiKind ui and always runs locally.
The ui extension is responsible for spawning a browser on the user's workstation to load a URI provided by the argument of a command print.launchBrowser that it registers using vscode.commands.registerCommand
The workspace extension uses vscode.commands.executeCommand to invoke print.launchBrowser.
The point of this arrangement is to allow the browser to be launched on the workstation irrespective of whether the extension host is local or remote.
This should work. The following documentation explicitly says it works: https://code.visualstudio.com/api/advanced-topics/remote-extensions#communicating-between-extensions-using-commands
However, when I test it works only when both extensions run on the workstation.
Before anyone tells me to use vscode.env.openExternal(Uri) I am aware of this and am using it to launch the default browser, but this is no use for launching a non-default browser. Many of my users exploit the support for an alternate browser to use Chrome for printing while using a less invasive alternative as their daily drive.
What could cause this to fail? Here's the abovementioned documentation:
Some extensions return APIs as a part of their activation that are intended for use by other extensions (via vscode.extension.getExtension(extensionName).exports). While these will work if all extensions involved are on the same side (either all UI Extensions or all Workspace Extensions), these will not work between UI and Workspace Extensions.
Fortunately, VS Code automatically routes any executed commands to the correct extension regardless of its location. You can freely invoke any command (including those provided by other extensions) without worrying about impacts.
That's not ambiguous.
Since the code for the browser agent is very short I present it in its entirety.
import * as vscode from 'vscode';
import * as child_process from "child_process";
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand("print.launchBrowser", url => {
const browserPath = vscode.workspace.getConfiguration("print").browserPath;
child_process.exec(`${escapePath(browserPath)} ${url}`, (error: child_process.ExecException | null, stdout: string, stderr: string) => {
if (error || stderr) {
const err = error ? error.message : stderr;
if (!err.startsWith("[")) {
vscode.window.showErrorMessage(err);
}
}
});
}));
}
function escapePath(path: string) {
switch (process.platform) {
case "win32":
return path.includes('"') || !path.includes(" ") ? path : `"${path}"`;
default:
return path.replace(/ /g, "\\ ");
}
}
Code to call it is straightforward. Any extension containing the following should open a browser window and load the bing.com default page, although if you want to use the agent above you'll need to either supply the print.browserPath setting with a value containing the workstation path to a browser or put in such a path as a literal for testing purposes.
There aren't any tests for things like whether browserPath has a value that resolves to a file. That's all in the calling extension, which is designed to use the agent only when it runs in a remote workspace. The agent is essentially nothing but a platform independent remote procedure call.
vscode.commands.executeCommand("print.launchBrowser", "https://bing.com");
All this has been tested and failed on two separate computers and also with VS Code Insiders 1.75.0, which also resolves the question of whether I have a borked VS Code installation.

Changing the configuration of TF6250-Modbus-TCP when used in TwinCAT/BSD

I have a device running TwinCAT/BSD.
Following section 5 the manual for TwinCAT/BSD I have successfully managed to install the TF6250 package. After updating the firewall rules I have confirmed that I am able connect and issue modbus tcp requests successfully using the Default Configuration from section 4.3 of the TF6250 manual.
My project requires mapping that is different from the default (i.e to the %Q registers rather than %M). Normally (when not not using TwinCAT/BSD) I would be able to edit my mapping via the Modbus TCP Configurator, but there does not appear to be an equivalent tool contained in the package for TwinCAT/BSD.
I have tried copying the mapping files that I would have created in the configurator into the Server directory with no luck. Are you able to tell me how my mapping can be updated in the TwinCAT/BSD environment?
If relevant:
TwinCAT Build: 3.1.4024.19
TC/BSD: 12.2.9.1,2
TF6250-Modbus-TCP: 2.0.1.0_1
pkg repo: https://tcbsd.beckhoff.com/TCBSD/12/stable/packages
I spoke with Beckhoff support who told that TF6250 expects the xml file with the configuration here: /usr/local/etc/TwinCAT/Functions/TF6250-Modbus-TCP/TcModbusSrv.xml
I tested this and it appears to work so all you need to do;
Create the mapping file as per normal (e.g using the windows tool) and copy the file there.
Reboot the device to load the configuration from the file.

Jenkins attaching local image in email

I am facing a problem in following scenario.
i have configured am email to be send after the job is succeed in Jenkins. In that email i am attaching local image to send it over email to other users, using html
The problem i am facing here is once the mail is in my outlook inbox i can download and see the embedded image on my machine but when i open the same email on different user's machine its not displaying image its showing "X" mark.
Please help to resolve the issue.
OK , so assuming you are using a declarative pipeline (because im not sure if you are using pipeline or regular job), you can add this code to your post stage :
post {
always {
echo 'I have finished'
archiveArtifacts 'yourfile.html or any extension'
emailext attachLog: true,
attachmentsPattern: '*.html',
body: 'Smoke Test.\n\nPlease see attachment for Report and build Logs', subject: 'DO NOT REPLY: JENKINS Build Server Notification [${BUILD_STATUS}]${JOB_NAME} Build #${BUILD_NUMBER}', to: 'example#example.com'
}
if you attachment (in my case is yourfile.html) is in your root directory then *.html is good to pick it up, otherwise pass the absolute path to your attachment.
Note : that its better always to archive the artifacts or the files you are trying to use later in the build or in other builds.
Also, make sure you have email extension plugin: Email extension plugin

Enable Cloud Vision API to access a file on Cloud Storage

i have already seen there are some similar questions but none of them actually provide a full answer.
Since I cannot comment in that thread, i am opening a new one.
How do I address Brandon's comment below?
"...
In order to use the Cloud Vision API with a non-public GCS object,
you'll need to send OAuth authentication information along with your
request for a user or service account which has permission to read the
GCS object."?
I have the json file the system gave me as described here when I created the service account.
I am trying to run the api from a python script.
It is not clear how to use it.
I'd recommend to use the Vision API Client Library for python to perform the call. You can install it on your machine (ideally in a virtualenv) by running the following command:
pip install --upgrade google-cloud-vision
Next, You'll need to set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. For example, on a Linux machine you'd do it like this:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
Finally, you'll just have to call the Vision API client's method you desire (for example here the label_detection method) like so:
def detect_labels():
"""Detects labels in the file located in Google Cloud Storage."""
client = vision.ImageAnnotatorClient()
image = types.Image()
image.source.image_uri = "gs://bucket_name/path_to_image_object"
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
By initialyzing the client with no parameter, the library will automatically look for the GOOGLE_APPLICATION_CREDENTIALS environment variable you've previously set and run on behalf of this service account. If you granted it permissions to access the file, it'll run successfully.

Unable to configure SabreDAV to test Webdav and CardDAV

Steps I followed:
Downloaded the Sabredav zip file - unzipped it.
Downloaded apache webserver 2.2 and PHP 5.3
Then followed the instructions mentioned in the 'get Started' section on Sabredav website.
Created 'data and public' fiels (located them in /sabredav/vendor/)
Created the server.php file (located it in /sabredav/vendor/)
Now tried to open the server.php file in browser -
Here it opens using the file protocol..
Fails to open in expected - 'http ://mydomain/sabredav/server.php
Can anybody please help me on this ?
Thanks
In server.php, use the browser plugin tu see files in Public folder.
Your server must be like this:
include 'SabreDAV/vendor/autoload.php';
use
Sabre\DAV;
$rootDirectory = new DAV\FS\Directory('public');
// The server object is responsible for making sense out of the WebDAV protocol
$server = new DAV\Server($rootDirectory);
// If your server is not on your webroot, make sure the following line has the correct information
$server->setBaseUri('/server.php'); // if its in some kind of home directory
// The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different
// directory, if you're storing your data somewhere else.
$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
$plugin = new \Sabre\DAV\Browser\Plugin();
$server->addPlugin($plugin);
// All we need to do now, is to fire up the server
$server->exec();