Alter scripts to be called by usb-detect
This commit is contained in:
parent
7a325ec7de
commit
20e8684d5b
@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
Rscript OpusData.R Rng02_Rng2630_02.0
|
File diff suppressed because it is too large
Load Diff
21
OpusData.R
21
OpusData.R
@ -1,25 +1,24 @@
|
||||
#!/usr/bin/env Rscript
|
||||
|
||||
# Attach packages to workspace, execute with every new session
|
||||
library("filesstrings")
|
||||
source("ReadOpus.R")
|
||||
|
||||
# Determine file path
|
||||
path <- commandArgs(trailingOnly = TRUE)[1]
|
||||
file_name <- commandArgs(trailingOnly = TRUE)[2]
|
||||
file_path <- paste0(path, file_name)
|
||||
#path <- commandArgs(trailingOnly = TRUE)[1]
|
||||
#file_name <- commandArgs(trailingOnly = TRUE)[2]
|
||||
#file_path <- paste0(path, file_name)
|
||||
file_path <- commandArgs(trailingOnly = TRUE)[1]
|
||||
|
||||
print(file_path)
|
||||
|
||||
# Convert opus binary file into dataframe
|
||||
data <- read_opus_univ(file_path, 5)
|
||||
|
||||
# Move the file to OPUS_old where it will remain temporarily in case of an error
|
||||
file.move(file_path, "OPUS_old/", overwrite = TRUE)
|
||||
|
||||
# Replace last "." with "_", add ".DPT"
|
||||
file_name <- paste0(sub(".([^.]*)$", "_\\1", file_name), ".DPT")
|
||||
#file_name <- paste0(sub(".([^.]*)$", "_\\1", file_name), ".DPT")
|
||||
|
||||
# Determine target, where the result should appear
|
||||
target_path <- paste0(path, "../DPT/", file_name)
|
||||
target_path <- paste0("/tmp/", sub('.*\\/', "", file_path))
|
||||
|
||||
# Create file
|
||||
file.create(target_path)
|
||||
@ -28,7 +27,7 @@ file.create(target_path)
|
||||
write.table(data, target_path, row.names = FALSE, col.names = FALSE, sep = ",")
|
||||
|
||||
# Call python script
|
||||
system(paste('python3 transferData.py', file_name))
|
||||
|
||||
system(paste('python3 transferData.py', target_path))
|
||||
#py_run_file("transfer.py",local=FALSE, convert=FALSE)
|
||||
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
inotifywait -m -q OPUS -e create -e moved_to |
|
||||
while read fpath action file; do
|
||||
Rscript OpusData.R $fpath $file >& /dev/null
|
||||
done
|
@ -1,11 +1,15 @@
|
||||
import requests
|
||||
import sys
|
||||
import re
|
||||
|
||||
file_name = sys.argv[1]
|
||||
dptFile = open("DPT/" + file_name, 'r')
|
||||
print(file_name)
|
||||
|
||||
dptFile = open(file_name, 'r')
|
||||
lines = dptFile.readlines()
|
||||
|
||||
jsonString = '['
|
||||
subject = re.split("(?<=_)(.+)(?=_)", file_name)[1]
|
||||
jsonString = '{\" + subject + \": ['
|
||||
|
||||
# Concatenate data
|
||||
for line in lines:
|
||||
@ -14,12 +18,16 @@ for line in lines:
|
||||
|
||||
# Remove last comma
|
||||
jsonString = jsonString[:-1]
|
||||
jsonString += ']'
|
||||
jsonString += ']}'
|
||||
|
||||
headers = {
|
||||
'accept': '*/*',
|
||||
'Authorization': 'Basic ZGVmaW5tYV9jb25uZWN0X1JuZ0B0YTJlMzViYjkyZDRjNDkyZDgwMjdkNDMyOTMxNzBkMDRfaHViOkRlZmlubWE=',
|
||||
'Content-Type': 'application/json',
|
||||
'accept': '*/*',
|
||||
'hono-ttd': '10',
|
||||
'Authorization': 'Basic ZGVmaW5tYUB0MzhiYmNjZDE2MjE3NDViODgxMTk5ZGI2ZWQzZGFiNmE6RGVGaW5NYWNoZW4yMDIwIQ==',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
data = '{"topic":"definma_connect/Rng/things/twin/commands/modify", "path":"features/data","value":{"properties":' + jsonString + '}}'
|
||||
response = requests.post('https://http.bosch-iot-hub.com/telemetry', headers=headers, data=jsonString)
|
||||
|
||||
print(response)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user