[1.0.0] First Version
This commit is contained in:
parent
5e1a38fd9e
commit
82f19ec1fa
@ -70,5 +70,18 @@
|
|||||||
<Name>Utils</Name>
|
<Name>Utils</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="config-example\settings.conf.example">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="dpkg\control" />
|
||||||
|
<None Include="dpkg\create-Builds.bat" />
|
||||||
|
<None Include="dpkg\monicascral-logrotate" />
|
||||||
|
<None Include="dpkg\monicascral.service" />
|
||||||
|
<None Include="dpkg\make-deb.sh" />
|
||||||
|
<None Include="dpkg\postinst" />
|
||||||
|
<None Include="dpkg\preinst" />
|
||||||
|
<None Include="dpkg\prerm" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -12,50 +12,50 @@ namespace Fraunhofer.Fit.IoT.MonicaScral {
|
|||||||
static void Main(String[] args) => new Program(args);
|
static void Main(String[] args) => new Program(args);
|
||||||
|
|
||||||
public Program(String[] args) {
|
public Program(String[] args) {
|
||||||
MqttListener m = new MqttListener(new Dictionary<String, String>() { { "type", "mqtt" }, { "server", "10.100.0.20" }, { "topic", "lora/data/+;lora/panic/+" } });
|
InIReader.SetSearchPath(new List<String>() { "/etc/monicascral", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\monicascral" });
|
||||||
ScralPusher s = new ScralPusher(new Dictionary<String, String>() {
|
if(!InIReader.ConfigExist("settings")) {
|
||||||
{ "server", "http://monappdwp3.monica-cloud.eu:8250" },
|
Helper.WriteError("No settings.ini found. Abord!");
|
||||||
{ "register_addr", "/scral/v1.0/gps-tracker-gw/gps-tag" },
|
return;
|
||||||
{ "register_method", "post" },
|
}
|
||||||
{ "update_addr", "/scral/v1.0/gps-tracker-gw/gps-tag/localization" },
|
InIReader settings = InIReader.GetInstance("settings");
|
||||||
{ "update_method", "put" },
|
this.logger.SetPath(settings.GetValue("logging", "path"));
|
||||||
{ "panic_addr", "/scral/v1.0/gps-tracker-gw/gps-tag/alert" },
|
MqttListener m = new MqttListener(settings.GetSection("mqtt"));
|
||||||
{ "panic_method", "put" },});
|
ScralPusher s = new ScralPusher(settings.GetSection("scral"));
|
||||||
m.Update += s.DataInput;
|
m.Update += s.DataInput;
|
||||||
this.WaitForShutdown();
|
this.WaitForShutdown();
|
||||||
m.Dispose();
|
m.Dispose();
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void WaitForShutdown() {
|
protected void WaitForShutdown() {
|
||||||
if(Type.GetType("Mono.Runtime") != null) {
|
if(Type.GetType("Mono.Runtime") != null) {
|
||||||
this.sig_thread = new Thread(delegate () {
|
this.sig_thread = new Thread(delegate () {
|
||||||
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
|
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
|
||||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
||||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
|
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
|
||||||
};
|
};
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono attached.");
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono attached.");
|
||||||
while(true) {
|
while(true) {
|
||||||
Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1);
|
Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1);
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono INT recieved " + i + ".");
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono INT recieved " + i + ".");
|
||||||
this.RunningProcess = false;
|
this.RunningProcess = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.sig_thread.Start();
|
this.sig_thread.Start();
|
||||||
} else {
|
} else {
|
||||||
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
|
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
|
||||||
}
|
}
|
||||||
while(this.RunningProcess) {
|
while(this.RunningProcess) {
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
|
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
|
||||||
this.RunningProcess = false;
|
this.RunningProcess = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Resources;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||||
// die einer Assembly zugeordnet sind.
|
// die einer Assembly zugeordnet sind.
|
||||||
[assembly: AssemblyTitle("MonicaScral")]
|
[assembly: AssemblyTitle("MonicaScral")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("Pushes Loratracker data to Monica Scral endpoint")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("Fraunhofer FIT")]
|
||||||
[assembly: AssemblyProduct("MonicaScral")]
|
[assembly: AssemblyProduct("MonicaScral")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
[assembly: AssemblyCopyright("Copyright © 2019 - 17.04.2019")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("Fraunhofer FIT, BlubbFish")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||||
@ -32,5 +33,9 @@ using System.Runtime.InteropServices;
|
|||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||||
// übernehmen, indem Sie "*" eingeben:
|
// übernehmen, indem Sie "*" eingeben:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0")]
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1.0.0 First Version
|
||||||
|
*/
|
||||||
|
@ -117,21 +117,21 @@ namespace Fraunhofer.Fit.IoT.MonicaScral {
|
|||||||
private String RequestString(String address, String json = "", Boolean withoutput = true, RequestMethod method = RequestMethod.GET) {
|
private String RequestString(String address, String json = "", Boolean withoutput = true, RequestMethod method = RequestMethod.GET) {
|
||||||
String ret = null;
|
String ret = null;
|
||||||
lock(this.getLock) {
|
lock(this.getLock) {
|
||||||
HttpWebRequest request = WebRequest.CreateHttp(this.config["server"] + address);
|
|
||||||
request.Timeout = 2000;
|
|
||||||
if(this.authRequired) {
|
|
||||||
request.Headers.Add(HttpRequestHeader.Authorization, this.auth);
|
|
||||||
}
|
|
||||||
if(method == RequestMethod.POST || method == RequestMethod.PUT) {
|
|
||||||
Byte[] requestdata = Encoding.ASCII.GetBytes(json);
|
|
||||||
request.ContentLength = requestdata.Length;
|
|
||||||
request.Method = method.ToString();
|
|
||||||
request.ContentType = "application/json";
|
|
||||||
using(Stream stream = request.GetRequestStream()) {
|
|
||||||
stream.Write(requestdata, 0, requestdata.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
HttpWebRequest request = WebRequest.CreateHttp(this.config["server"] + address);
|
||||||
|
request.Timeout = 2000;
|
||||||
|
if(this.authRequired) {
|
||||||
|
request.Headers.Add(HttpRequestHeader.Authorization, this.auth);
|
||||||
|
}
|
||||||
|
if(method == RequestMethod.POST || method == RequestMethod.PUT) {
|
||||||
|
Byte[] requestdata = Encoding.ASCII.GetBytes(json);
|
||||||
|
request.ContentLength = requestdata.Length;
|
||||||
|
request.Method = method.ToString();
|
||||||
|
request.ContentType = "application/json";
|
||||||
|
using(Stream stream = request.GetRequestStream()) {
|
||||||
|
stream.Write(requestdata, 0, requestdata.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
|
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
|
||||||
if(response.StatusCode == HttpStatusCode.Unauthorized) {
|
if(response.StatusCode == HttpStatusCode.Unauthorized) {
|
||||||
Console.Error.WriteLine("Benutzer oder Passwort falsch!");
|
Console.Error.WriteLine("Benutzer oder Passwort falsch!");
|
||||||
|
16
MonicaScral/config-example/settings.conf.example
Normal file
16
MonicaScral/config-example/settings.conf.example
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[logging]
|
||||||
|
path=/var/log/monicascral.log
|
||||||
|
|
||||||
|
[mqtt]
|
||||||
|
type=mqtt
|
||||||
|
server=127.0.01
|
||||||
|
topic=lora/data/+;lora/panic/+
|
||||||
|
|
||||||
|
[scral]
|
||||||
|
server=http://example.org:8080
|
||||||
|
register_addr=/gps-tag
|
||||||
|
register_method=post
|
||||||
|
update_addr=/gps-tag/localization
|
||||||
|
update_method=put
|
||||||
|
panic_addr=/gps-tag/alert
|
||||||
|
panic_method=put
|
9
MonicaScral/dpkg/control
Normal file
9
MonicaScral/dpkg/control
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Package: monicascral
|
||||||
|
Version: x.x-x
|
||||||
|
Section: base
|
||||||
|
Priority: optional
|
||||||
|
Architecture: any
|
||||||
|
Depends: mono-runtime (>= 5.18), libmono-posix4.0-cil (>= 5.18)
|
||||||
|
Maintainer: BlubbFish <dev@blubbfish.net>
|
||||||
|
Description: MonicaScral
|
||||||
|
Pushes Loratracker data to Monica Scral endpoint
|
2
MonicaScral/dpkg/create-Builds.bat
Normal file
2
MonicaScral/dpkg/create-Builds.bat
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bash.exe -c "./make-deb.sh amd64"
|
||||||
|
pause
|
49
MonicaScral/dpkg/make-deb.sh
Normal file
49
MonicaScral/dpkg/make-deb.sh
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
HOMEDIR=$HOME
|
||||||
|
ROOT="$HOMEDIR/deb"
|
||||||
|
OUTPUT="../bin/Release"
|
||||||
|
|
||||||
|
EXEC="$ROOT/usr/local/bin/monicascral"
|
||||||
|
CONFIG="$ROOT/etc/monicascral"
|
||||||
|
SYSTEMD="$ROOT/lib/systemd/system"
|
||||||
|
LOGROTATE="$ROOT/etc/logrotate.d"
|
||||||
|
|
||||||
|
DEBIAN="$ROOT/DEBIAN"
|
||||||
|
VMAJOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 1)
|
||||||
|
VMINOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 2)
|
||||||
|
VBUILD=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 3)
|
||||||
|
ARCHT=$1
|
||||||
|
|
||||||
|
mkdir -p $EXEC
|
||||||
|
mkdir -p $CONFIG
|
||||||
|
mkdir -p $DEBIAN
|
||||||
|
mkdir -p $SYSTEMD
|
||||||
|
mkdir -p $LOGROTATE
|
||||||
|
|
||||||
|
cp control $DEBIAN
|
||||||
|
cp preinst $DEBIAN
|
||||||
|
cp postinst $DEBIAN
|
||||||
|
cp prerm $DEBIAN
|
||||||
|
sed -i s/Version:\ x\.x-x/"Version: $VMAJOR.$VMINOR-$VBUILD"/ $DEBIAN/control
|
||||||
|
sed -i s/Architecture:\ any/"Architecture: $ARCHT"/ $DEBIAN/control
|
||||||
|
chmod 755 $DEBIAN -R
|
||||||
|
|
||||||
|
cp monicascral.service $SYSTEMD
|
||||||
|
chmod 644 $SYSTEMD/monicascral.service
|
||||||
|
|
||||||
|
cp $OUTPUT/*.exe $EXEC/
|
||||||
|
find $OUTPUT -name \*.dll -exec cp {} $EXEC/ \;
|
||||||
|
chmod 644 $EXEC/*
|
||||||
|
chmod 755 $EXEC
|
||||||
|
|
||||||
|
cp $OUTPUT/config-example/* $CONFIG
|
||||||
|
chmod 644 $CONFIG/*
|
||||||
|
chmod 755 $CONFIG
|
||||||
|
|
||||||
|
cp monicascral-logrotate $LOGROTATE/monicascral
|
||||||
|
chmod 644 $LOGROTATE/*
|
||||||
|
|
||||||
|
dpkg-deb --build $ROOT
|
||||||
|
mv $HOMEDIR/deb.deb ../../../Builds/"$ARCHT-monicascral_$VMAJOR.$VMINOR-$VBUILD.deb"
|
||||||
|
rm $HOMEDIR/deb -r
|
10
MonicaScral/dpkg/monicascral-logrotate
Normal file
10
MonicaScral/dpkg/monicascral-logrotate
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/var/log/monicascral.log {
|
||||||
|
compress
|
||||||
|
copytruncate
|
||||||
|
daily
|
||||||
|
delaycompress
|
||||||
|
missingok
|
||||||
|
notifempty
|
||||||
|
rotate 4
|
||||||
|
size=10M
|
||||||
|
}
|
20
MonicaScral/dpkg/monicascral.service
Normal file
20
MonicaScral/dpkg/monicascral.service
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# If you modify this, please also make sure to edit init.sh
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=MonicaScral
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=root
|
||||||
|
Group=root
|
||||||
|
WorkingDirectory=/usr/local/bin/monicascral
|
||||||
|
ExecStart=/usr/bin/mono /usr/local/bin/monicascral/MonicaScral.exe
|
||||||
|
KillMode=control-group
|
||||||
|
TimeoutStopSec=5
|
||||||
|
Restart=on-failure
|
||||||
|
StandardOutput=null
|
||||||
|
StandardError=syslog
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
Alias=monicascral.service
|
9
MonicaScral/dpkg/postinst
Normal file
9
MonicaScral/dpkg/postinst
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
systemctl enable monicascral
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
if [ -f /tmp/monicascral_service_runner ]; then
|
||||||
|
service monicascral start
|
||||||
|
rm /tmp/monicascral_service_runner
|
||||||
|
fi
|
2
MonicaScral/dpkg/preinst
Normal file
2
MonicaScral/dpkg/preinst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
7
MonicaScral/dpkg/prerm
Normal file
7
MonicaScral/dpkg/prerm
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ $(systemctl is-active monicascral || true) == "active" ]]
|
||||||
|
then
|
||||||
|
touch /tmp/monicascral_service_runner
|
||||||
|
service monicascral stop
|
||||||
|
fi
|
Reference in New Issue
Block a user