raspberry
This commit is contained in:
1 parent
84dfdf5210
commit
be436085b3
55 files changed
+2195
No files matched your search
Binary file not shown.
@@ -0,0 +1,172 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/rfcomm.h>
|
||||||
|
#include <bluetooth/hci.h>
|
||||||
|
#include <bluetooth/hci_lib.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
void log(string log_str, struct tm * timeinfo)
|
||||||
|
{
|
||||||
|
char logname[35];
|
||||||
|
memset(logname,0,sizeof(logname));
|
||||||
|
sprintf(logname,"/home/lucas/.LOG/BTlog%.2i%.2i.txt",timeinfo->tm_mon+1,timeinfo->tm_mday);
|
||||||
|
system("find /home/lucas/.LOG/BTlog* -mtime +10 -type f -delete");
|
||||||
|
ofstream logfile(logname, ios::app);
|
||||||
|
if(logfile.is_open())
|
||||||
|
{
|
||||||
|
logfile << timeinfo->tm_mon<<"."<<timeinfo->tm_mday<<";"<<timeinfo->tm_hour<<":"<<timeinfo->tm_min<<":"<<timeinfo->tm_sec<<": BTserver: "<< log_str <<"\n";
|
||||||
|
logfile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int exec_cmd(int cmd_value,struct tm *timeinfo){
|
||||||
|
string key,cmd=string("irsend SEND_ONCE SAMSUNG ");
|
||||||
|
switch(cmd_value){
|
||||||
|
case 1://ON
|
||||||
|
key=string("KEY_0"); break;
|
||||||
|
case 2://Up
|
||||||
|
key=string("KEY_UP"); break;
|
||||||
|
case 3://OFF
|
||||||
|
key=string("KEY_POWER"); break;
|
||||||
|
case 4://Left
|
||||||
|
key=string("KEY_LEFT"); break;
|
||||||
|
case 5://Enter
|
||||||
|
key=string("KEY_ENTER"); break;
|
||||||
|
case 6://Right
|
||||||
|
key=string("KEY_RIGHT"); break;
|
||||||
|
case 7://Volume UP
|
||||||
|
key=string("KEY_VOLUMEUP"); break;
|
||||||
|
case 8://Down
|
||||||
|
key=string("KEY_DOWN"); break;
|
||||||
|
case 9://Volume Down
|
||||||
|
key=string("KEY_VOLUMEDOWN"); break;
|
||||||
|
case 10://Source
|
||||||
|
key=string("KEY_MEDIA"); break;
|
||||||
|
case 11://Play
|
||||||
|
key=string("KEY_PLAY"); break;
|
||||||
|
case 12://Pause
|
||||||
|
key=string("KEY_PAUSE"); break;
|
||||||
|
case 13://Mute
|
||||||
|
key=string("KEY_MUTE"); break;
|
||||||
|
case 14://Mute
|
||||||
|
key=string("KEY_BACK"); break;
|
||||||
|
case 15://Mute
|
||||||
|
key=string("KEY_EXIT"); break;
|
||||||
|
default: log(to_string(cmd_value),timeinfo); return 1;
|
||||||
|
}
|
||||||
|
cmd.append(key);
|
||||||
|
if(system(cmd.c_str())==0)
|
||||||
|
{
|
||||||
|
log(key,timeinfo);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else return -1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int setBTdevice(int device, struct tm * timeinfo)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
struct sockaddr_rc loc_addr = { 0 };
|
||||||
|
struct hci_dev_info di;
|
||||||
|
// allocate socket
|
||||||
|
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
|
||||||
|
|
||||||
|
// bind socket to port 1 of the first available
|
||||||
|
// local bluetooth adapter
|
||||||
|
if(hci_devinfo(device, &di) < 0)
|
||||||
|
{
|
||||||
|
log("HCI device info failed",timeinfo);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
string dev_log=string("Local device: ")+ batostr(&di.bdaddr);
|
||||||
|
log(dev_log,timeinfo);
|
||||||
|
loc_addr.rc_bdaddr = di.bdaddr;
|
||||||
|
loc_addr.rc_family = AF_BLUETOOTH;
|
||||||
|
loc_addr.rc_channel = (uint8_t) 1;
|
||||||
|
if(bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)) < 0)
|
||||||
|
{
|
||||||
|
log("Socket bind Error",timeinfo);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
cout << "Usage:\n<1/0> BTdevice"<<endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
struct sockaddr_rc rem_addr = { 0 };
|
||||||
|
socklen_t opt = sizeof(rem_addr);
|
||||||
|
struct tm * timeinfo;
|
||||||
|
time_t rawtime;
|
||||||
|
time ( &rawtime );
|
||||||
|
timeinfo= localtime ( &rawtime );
|
||||||
|
log("Start Bluetooth Server",timeinfo);
|
||||||
|
string LF_phone=string("34:14:5F:68:FC:EC");
|
||||||
|
char buf[1024] = { 0 };
|
||||||
|
int sock, client, bytes_read,device=atoi(argv[1]);
|
||||||
|
sock=setBTdevice(device,timeinfo);
|
||||||
|
if(sock==0) log("Socket Failure",timeinfo);
|
||||||
|
|
||||||
|
// put socket into listening mode
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
listen(sock, 1);
|
||||||
|
log("Device in Listening Mode",timeinfo);
|
||||||
|
// accept one connection
|
||||||
|
client = accept(sock, (struct sockaddr *)&rem_addr, &opt);
|
||||||
|
if(client < 0)
|
||||||
|
{
|
||||||
|
log("Client accept Error",timeinfo);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string dev_addr;
|
||||||
|
ba2str( &rem_addr.rc_bdaddr,buf );
|
||||||
|
dev_addr.assign(buf);
|
||||||
|
|
||||||
|
if(dev_addr.compare(LF_phone)!=0)
|
||||||
|
{
|
||||||
|
log("Illegal Connection Attempt",timeinfo);
|
||||||
|
close(client);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string log_str=string("Accepted connection from: ")+dev_addr;
|
||||||
|
log(log_str,timeinfo);
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
// if(string())
|
||||||
|
// read data from the client
|
||||||
|
bytes_read = read(client, buf, sizeof(buf));
|
||||||
|
while( bytes_read > 0 )
|
||||||
|
{
|
||||||
|
time ( &rawtime );
|
||||||
|
timeinfo= localtime ( &rawtime );
|
||||||
|
bytes_read = read(client, buf, sizeof(buf));
|
||||||
|
if(exec_cmd(atoi(buf),timeinfo)<0)
|
||||||
|
{
|
||||||
|
log_str.assign("Remote Command Failed: " + string(buf));
|
||||||
|
log(log_str,timeinfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
}
|
||||||
|
close(client);
|
||||||
|
log_str.assign("Disconnected from: "+dev_addr);
|
||||||
|
log(log_str,timeinfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// close connection
|
||||||
|
close(sock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/rfcomm.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
|
||||||
|
struct hci_dev_info di;
|
||||||
|
char buf[1024] = { 0 };
|
||||||
|
int s, client, bytes_read;
|
||||||
|
socklen_t opt = sizeof(rem_addr);
|
||||||
|
char address[18] = "XX:XX:XX:XX:XX:XX";
|
||||||
|
// allocate socket
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
cout << "Usage:\n<0/1> BTdevice" << endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
|
||||||
|
{
|
||||||
|
perror("socket");
|
||||||
|
}
|
||||||
|
if(hci_devinfo(0, &di) < 0)
|
||||||
|
{
|
||||||
|
perror("HCI device info failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
cout << "Local device: " << batostr(&di.bdaddr)) << endl;
|
||||||
|
laddr.rc_family = AF_BLUETOOTH;
|
||||||
|
laddr.rc_bdaddr = di.bdaddr;
|
||||||
|
laddr.rc_channel = 2;
|
||||||
|
|
||||||
|
// bind socket to port 1 of the first available
|
||||||
|
// local bluetooth adapter
|
||||||
|
bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
|
||||||
|
{
|
||||||
|
perror("bind");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// put socket into listening mode
|
||||||
|
listen(s, 1);
|
||||||
|
|
||||||
|
// accept one connection
|
||||||
|
client = accept(s, (struct sockaddr *)&rem_addr, &opt);
|
||||||
|
|
||||||
|
ba2str( &rem_addr.rc_bdaddr, buf );
|
||||||
|
uuuuustderr, "accepted connection from %s\n", buf);
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
|
// read data from the client
|
||||||
|
bytes_read = read(client, buf, sizeof(buf));
|
||||||
|
if( bytes_read > 0 ) {
|
||||||
|
printf("received [%s]\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// close connection
|
||||||
|
close(client);
|
||||||
|
close(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Whitespace-only changes.
Binary file not shown.
@@ -0,0 +1,68 @@
|
|||||||
|
#include "/home/lucas/433Utils/rc-switch/RCSwitch.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
RCSwitch mySwitch;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
// This pin is not the first pin on the RPi GPIO header!
|
||||||
|
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
|
||||||
|
// for more information.
|
||||||
|
int PIN = 2; //G27
|
||||||
|
|
||||||
|
if(wiringPiSetup() == -1) {
|
||||||
|
printf("wiringPiSetup failed, exiting...");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pulseLength = 0;
|
||||||
|
if (argv[1] != NULL) pulseLength = atoi(argv[1]);
|
||||||
|
|
||||||
|
mySwitch = RCSwitch();
|
||||||
|
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
|
||||||
|
mySwitch.enableReceive(PIN); // Receiver on interrupt 0 => that is pin #2
|
||||||
|
unsigned long value;
|
||||||
|
unsigned long previous=0;
|
||||||
|
int length;
|
||||||
|
int protocol;
|
||||||
|
unsigned int* raw;
|
||||||
|
struct timeval time1,time2;
|
||||||
|
long long elapsedTime;
|
||||||
|
int delay;
|
||||||
|
printf("Stetup Finished, Start Sniffing\n");
|
||||||
|
while(1) {
|
||||||
|
|
||||||
|
if (mySwitch.available()) {
|
||||||
|
|
||||||
|
value = mySwitch.getReceivedValue();
|
||||||
|
length = mySwitch.getReceivedBitlength();
|
||||||
|
protocol = mySwitch.getReceivedProtocol();
|
||||||
|
raw = mySwitch.getReceivedRawdata();
|
||||||
|
delay = mySwitch.getReceivedDelay();
|
||||||
|
if (value == 0)
|
||||||
|
{
|
||||||
|
printf("Unknown encoding\n");
|
||||||
|
}
|
||||||
|
else if (value != previous)
|
||||||
|
{
|
||||||
|
gettimeofday(&time1,NULL);
|
||||||
|
printf("Received %i\nLength: %i\nProtocol: %i\nDelay: %i\nRaw Data:\n", value,length,protocol, delay );
|
||||||
|
for (int i=0; i<= length*2; i++)
|
||||||
|
{
|
||||||
|
printf("%i",raw[i]);
|
||||||
|
printf(",");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
previous = value;
|
||||||
|
mySwitch.resetAvailable();
|
||||||
|
|
||||||
|
}
|
||||||
|
gettimeofday(&time2,NULL);
|
||||||
|
if ((time2.tv_sec - time1.tv_sec) > 2) previous=0;
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/rfcomm.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
|
||||||
|
char buf[1024] = { 0 };
|
||||||
|
int s, client, bytes_read;
|
||||||
|
socklen_t opt = sizeof(rem_addr);
|
||||||
|
|
||||||
|
// allocate socket
|
||||||
|
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
|
||||||
|
|
||||||
|
// bind socket to port 1 of the first available
|
||||||
|
// local bluetooth adapter
|
||||||
|
loc_addr.rc_family = AF_BLUETOOTH;
|
||||||
|
loc_addr.rc_bdaddr = "00:00:00:00:00:00";
|
||||||
|
loc_addr.rc_channel = (uint8_t) 1;
|
||||||
|
bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
|
||||||
|
|
||||||
|
// put socket into listening mode
|
||||||
|
listen(s, 1);
|
||||||
|
|
||||||
|
// accept one connection
|
||||||
|
client = accept(s, (struct sockaddr *)&rem_addr, &opt);
|
||||||
|
|
||||||
|
ba2str( &rem_addr.rc_bdaddr, buf );
|
||||||
|
fprintf(stderr, "accepted connection from %s\n", buf);
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
|
// read data from the client
|
||||||
|
bytes_read = read(client, buf, sizeof(buf));
|
||||||
|
if( bytes_read > 0 ) {
|
||||||
|
printf("received [%s]\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if( status < 0 ) perror("uh oh");
|
||||||
|
|
||||||
|
// close connection
|
||||||
|
close(client);
|
||||||
|
close(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/hci.h>
|
||||||
|
#include <bluetooth/hci_lib.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
inquiry_info *ii = NULL;
|
||||||
|
int max_rsp, num_rsp;
|
||||||
|
int dev_id, sock, len, flags;
|
||||||
|
int i;
|
||||||
|
char addr[19] = { 0 };
|
||||||
|
char name[248] = { 0 };
|
||||||
|
dev_id = hci_get_route(NULL);
|
||||||
|
sock = hci_open_dev( dev_id );
|
||||||
|
if (dev_id < 0 || sock < 0) {
|
||||||
|
perror("opening socket");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
len = 8;
|
||||||
|
max_rsp = 255;
|
||||||
|
flags = IREQ_CACHE_FLUSH;
|
||||||
|
ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
|
||||||
|
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
|
||||||
|
if( num_rsp < 0 ) perror("hci_inquiry");
|
||||||
|
for (i = 0; i < num_rsp; i++) {
|
||||||
|
ba2str(&(ii+i)->bdaddr, addr);
|
||||||
|
memset(name, 0, sizeof(name));
|
||||||
|
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
|
||||||
|
name, 0) < 0)
|
||||||
|
strcpy(name, "[unknown]");
|
||||||
|
printf("%s %s\n", addr, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
free( ii );
|
||||||
|
close( sock );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Binary file not shown.
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* BlueZ example code to build an rfcomm client.
|
||||||
|
* This code just creates a socket and connects
|
||||||
|
* to a remote bluetooth device and sends a string.
|
||||||
|
* Programmed by Bastian Ballmann
|
||||||
|
* http://www.geektown.de
|
||||||
|
* Compile with gcc -lbluetooth <executable> <source>
|
||||||
|
* */
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/rfcomm.h>
|
||||||
|
#include <bluetooth/hci.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <bluetooth/hci_lib.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int sock, bytes_read, bt_channel=1;
|
||||||
|
struct sockaddr_rc laddr, raddr;
|
||||||
|
struct hci_dev_info di;
|
||||||
|
char bt_addr[]="98:D3:31:FD:14:BC";
|
||||||
|
if(argc < 3)
|
||||||
|
{
|
||||||
|
printf("%s <btaddr> <channel>\n", argv[0]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if(hci_devinfo(0, &di) < 0)
|
||||||
|
{
|
||||||
|
perror("HCI device info failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("Local device %s\n", batostr(&di.bdaddr));
|
||||||
|
|
||||||
|
laddr.rc_family = AF_BLUETOOTH;
|
||||||
|
laddr.rc_bdaddr = di.bdaddr;
|
||||||
|
laddr.rc_channel = 0;
|
||||||
|
raddr.rc_family = AF_BLUETOOTH;
|
||||||
|
str2ba(argv[1],&raddr.rc_bdaddr);
|
||||||
|
raddr.rc_channel = atoi(argv[2]);
|
||||||
|
if( (sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0)
|
||||||
|
{
|
||||||
|
perror("socket");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bind(sock, (struct sockaddr *)&laddr, sizeof(laddr)) < 0)
|
||||||
|
{
|
||||||
|
perror("bind");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("Remote device %s\n", argv[1]);
|
||||||
|
if(connect(sock, (struct sockaddr *)&raddr, sizeof(raddr)) < 0)
|
||||||
|
{
|
||||||
|
perror("connect");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Connected.\nRecieving data\n");
|
||||||
|
//read data from the client
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
char buf[1024]={0};
|
||||||
|
bytes_read = read(sock, buf, sizeof(buf));
|
||||||
|
if( bytes_read > 0 ) {
|
||||||
|
printf("%s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
printf("Disconnect.\n");
|
||||||
|
close(sock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,217 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/rfcomm.h>
|
||||||
|
#include <bluetooth/hci.h>
|
||||||
|
#include <bluetooth/hci_lib.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
int BTsocket=0;
|
||||||
|
|
||||||
|
int mail(string mail_str)
|
||||||
|
{
|
||||||
|
struct tm * timeinfo;
|
||||||
|
time_t rawtime;
|
||||||
|
time ( &rawtime );
|
||||||
|
timeinfo= localtime ( &rawtime );
|
||||||
|
string recipient="lucas-f@live.at",cmd=string("printf \"Moist Sensor Alarm:\\n") + asctime(timeinfo) + string("\\n") + mail_str +string("\" | mail -s 'MS Alarm' " + recipient);
|
||||||
|
if(system(cmd.c_str())!=0) cout << "Failed to send Mail" << endl;
|
||||||
|
else cout << "Mail Sent" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void log(string log_str)
|
||||||
|
{
|
||||||
|
struct tm * timeinfo;
|
||||||
|
time_t rawtime;
|
||||||
|
time ( &rawtime );
|
||||||
|
timeinfo= localtime ( &rawtime );
|
||||||
|
ostringstream logname;
|
||||||
|
logname << "/home/lucas/.LOG/MSlog" << setfill('0') <<setw(2) << timeinfo->tm_mon+1 << setw(2) << timeinfo->tm_mday << ".txt";
|
||||||
|
system("find /home/lucas/.LOG/MSlog* -mtime +10 -type f -delete");
|
||||||
|
string filename=logname.str();
|
||||||
|
ofstream logfile(filename.c_str(), ios::app);
|
||||||
|
if(logfile.is_open())
|
||||||
|
{
|
||||||
|
logfile << timeinfo->tm_mon<<"."<<timeinfo->tm_mday<<";"<<timeinfo->tm_hour<<":"<<timeinfo->tm_min<<":"<<timeinfo->tm_sec<<": "<<log_str<<endl;
|
||||||
|
logfile.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mail("Log File Creation Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int setBTdevice(int device)
|
||||||
|
{
|
||||||
|
BTsocket=0;
|
||||||
|
int bt_channel=1;
|
||||||
|
struct sockaddr_rc laddr, raddr;
|
||||||
|
struct hci_dev_info di;
|
||||||
|
char bt_addr[]="98:D3:31:FD:14:BC";
|
||||||
|
if(hci_devinfo(device, &di) < 0)
|
||||||
|
{
|
||||||
|
log("HCI device info failed Errno: " + string(strerror(errno)));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
cout << "Local device " << batostr(&di.bdaddr) << endl;
|
||||||
|
|
||||||
|
laddr.rc_family = AF_BLUETOOTH;
|
||||||
|
laddr.rc_bdaddr = di.bdaddr;
|
||||||
|
laddr.rc_channel = 0;
|
||||||
|
raddr.rc_family = AF_BLUETOOTH;
|
||||||
|
str2ba(bt_addr,&raddr.rc_bdaddr);
|
||||||
|
raddr.rc_channel = bt_channel;
|
||||||
|
if( (BTsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) <0)
|
||||||
|
{
|
||||||
|
log("Function error: BTsocketet Errno: " + string(strerror(errno)));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_sec = 30; /* 30 Secs Timeout */
|
||||||
|
tv.tv_usec = 0; // Not init'ing this can cause strange errors
|
||||||
|
setsockopt(BTsocket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv,sizeof(struct timeval));
|
||||||
|
int reuse = 1;
|
||||||
|
setsockopt(BTsocket,SOL_SOCKET,SO_REUSEPORT,&reuse,sizeof(int));
|
||||||
|
if(bind(BTsocket, (struct sockaddr *)&laddr, sizeof(laddr)) < 0)
|
||||||
|
{
|
||||||
|
log("Function error: bind Errno: " + string(strerror(errno)));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
if(connect(BTsocket, (struct sockaddr *)&raddr, sizeof(raddr)) <0)
|
||||||
|
{
|
||||||
|
if(errno != EINPROGRESS)
|
||||||
|
{
|
||||||
|
log("Function error: connect. Errno: " + string(strerror(errno)));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fd_set readfds;
|
||||||
|
|
||||||
|
FD_ZERO(&readfds);
|
||||||
|
FD_SET(BTsocket, &readfds);
|
||||||
|
//We are going to use select to wait for the BTsocketet to connect
|
||||||
|
struct timeval sel_to; //Time value struct declaration
|
||||||
|
sel_to.tv_sec = 5; //The second portion of the struct
|
||||||
|
sel_to.tv_usec = 0; //The microsecond portion of the struct
|
||||||
|
|
||||||
|
//DEBUG: This is ALWAYS 1
|
||||||
|
if(select(BTsocket + 1, &readfds, NULL, NULL, &sel_to)<=0)
|
||||||
|
{
|
||||||
|
log("Function error: select. Errno: " + string(strerror(errno)));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
cout << "Connected To Arduino" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reconnectBT(int BTsocket){
|
||||||
|
int bt_channel=1;
|
||||||
|
char bt_addr[]="98:D3:31:FD:14:BC";
|
||||||
|
struct sockaddr_rc raddr;
|
||||||
|
raddr.rc_family = AF_BLUETOOTH;
|
||||||
|
str2ba(bt_addr,&raddr.rc_bdaddr);
|
||||||
|
raddr.rc_channel = bt_channel;
|
||||||
|
if(connect(BTsocket, (struct sockaddr *)&raddr, sizeof(raddr)) <0)
|
||||||
|
{
|
||||||
|
log("Function error: connect. Errno: " + string(strerror(errno)) +" Socket: " + to_string(BTsocket) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cout << "Connected To Arduino" << endl;
|
||||||
|
return BTsocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc<4)
|
||||||
|
{
|
||||||
|
cout << "Usage: <m/x> Mail/no Mail\n<i> delay\n<0/1> BTdevice"<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cout << "Start Moisture Sensor Reciever\n" << "Usage: argv[1] m for Mail ON x for Mail OFF"<<endl;
|
||||||
|
struct timeval time1;
|
||||||
|
int sleeptime=atoi(argv[2]),connection_retries=100,device=atoi(argv[3]);
|
||||||
|
int limit=100;
|
||||||
|
//sleeptime=;
|
||||||
|
bool msg=false;
|
||||||
|
if(strchr(argv[1],'m')!=NULL)
|
||||||
|
{
|
||||||
|
msg=true;
|
||||||
|
cout << "Mail ON\n";
|
||||||
|
}
|
||||||
|
if(device!=0&&device!=1)
|
||||||
|
{
|
||||||
|
cout << "Wrong BT Device" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int ret,i;
|
||||||
|
ret=setBTdevice(device);
|
||||||
|
for(i=0;i<connection_retries&&ret!=0;i++){
|
||||||
|
if(BTsocket!=0) close(BTsocket);
|
||||||
|
sleep(sleeptime);
|
||||||
|
ret=setBTdevice(device);
|
||||||
|
if(i==connection_retries-1&&ret!=0)
|
||||||
|
{
|
||||||
|
cout << "Bluetooth Connection cannot be Established" << endl;
|
||||||
|
mail("Bluetooth Connection cannot be established. Errno: " + string(strerror(ret)));
|
||||||
|
log("Bluetooth Connection cannot be established. Errno: " + string(strerror(ret)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int bytes_read,value;
|
||||||
|
cout << "Setup Complete" << endl;
|
||||||
|
gettimeofday(&time1,NULL);
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
char buf[1024]={0};
|
||||||
|
bytes_read = read(BTsocket, buf, sizeof(buf));
|
||||||
|
if(bytes_read > 0)
|
||||||
|
{
|
||||||
|
value = atoi(buf);
|
||||||
|
cout << "Received " << value << endl;
|
||||||
|
if(value>=limit&&value<1200)
|
||||||
|
{
|
||||||
|
cout << "Value exceeds Limit!"<< endl;
|
||||||
|
if(msg) mail("Value exceeds Limit: " + to_string(value));
|
||||||
|
|
||||||
|
}
|
||||||
|
log("MSValue: " + to_string(value));
|
||||||
|
sleep(sleeptime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log("Read Error: " + to_string(bytes_read) + " [ Errno: " +to_string(errno) + " ] " + string(strerror(errno)) + "Socket: " + to_string(BTsocket));
|
||||||
|
cout << "Connection Lost" << endl;
|
||||||
|
for(i=0;i<connection_retries;i++)
|
||||||
|
{
|
||||||
|
close(BTsocket);
|
||||||
|
sleep(sleeptime);
|
||||||
|
BTsocket=setBTdevice(device);
|
||||||
|
if(ret==0&&BTsocket!=0)
|
||||||
|
{
|
||||||
|
log("Bluetooth Connection temporarily Lost, reestablished after " + to_string(i) + " retries" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(i==connection_retries-1&&ret!=0)
|
||||||
|
{
|
||||||
|
cout << "Bluetooth Connection not possible!" << endl;
|
||||||
|
log("Bluetooth Connection Lost. Errno: " + string(strerror(ret)));
|
||||||
|
mail("Bluetooth Connection Lost. Errno: " + string(strerror(ret)));
|
||||||
|
close(BTsocket);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,41 @@
|
|||||||
|
//compile with -lwiringPi
|
||||||
|
//g++ -pthread ../../wiringPi/433Utils/rc-switch/RCSwitch.o sendRC_Schlafzimmer.cpp -o sendRC_Schlafzimmer -lwiringPi
|
||||||
|
#include "/home/lucas/wiringPi/433Utils/rc-switch/RCSwitch.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
extern "C" {
|
||||||
|
#include <wiringPi.h>
|
||||||
|
}
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
// This pin is not the first pin on the RPi GPIO header!
|
||||||
|
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
|
||||||
|
// for more information.
|
||||||
|
int PIN = 0;//G17
|
||||||
|
|
||||||
|
// Parse the first parameter to this command as an integer
|
||||||
|
int protocol = 2; // A value of 0 will use rc-switch's default value
|
||||||
|
int pulseLength = 0;
|
||||||
|
int length = 24;
|
||||||
|
string arg=string(argv[1]);
|
||||||
|
// Change protocol and pulse length accroding to parameters
|
||||||
|
int code=0;
|
||||||
|
if(arg.compare("OFF")==0) code=891819008;
|
||||||
|
else if(arg.compare("ON")==0) code=958927872;
|
||||||
|
if (wiringPiSetup () == -1) return 1;
|
||||||
|
cout << "Switching " << arg << endl;
|
||||||
|
RCSwitch mySwitch = RCSwitch();
|
||||||
|
if (protocol != 0) mySwitch.setProtocol(protocol);
|
||||||
|
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
|
||||||
|
mySwitch.enableTransmit(PIN);
|
||||||
|
|
||||||
|
mySwitch.send(code, length);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
|||||||
|
#include "/home/lucas/433Utils/rc-switch/RCSwitch.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
// This pin is not the first pin on the RPi GPIO header!
|
||||||
|
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
|
||||||
|
// for more information.
|
||||||
|
int PIN = 0;//G17
|
||||||
|
|
||||||
|
// Parse the first parameter to this command as an integer
|
||||||
|
int protocol = 2; // A value of 0 will use rc-switch's default value
|
||||||
|
int pulseLength = 0;
|
||||||
|
int length = 24;
|
||||||
|
// If no command line argument is given, print the help text
|
||||||
|
if (argc == 1) {
|
||||||
|
printf("Usage: %s decimalcode [protocol] [length] [pulselength]\n", argv[0]);
|
||||||
|
printf("decimalcode\t- As decoded by RFSniffer\n");
|
||||||
|
printf("protocol\t- According to rc-switch definitions\n");
|
||||||
|
printf("length\t\t- Whatever the Fuck U want\n");
|
||||||
|
printf("pulselength\t- pulselength in microseconds\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change protocol and pulse length accroding to parameters
|
||||||
|
int code = atoi(argv[1]);
|
||||||
|
if (argc >= 3) protocol = atoi(argv[2]);
|
||||||
|
if (argc >= 4) length = atoi(argv[3]);
|
||||||
|
if (argc >= 5) pulseLength = atoi(argv[4]);
|
||||||
|
if (wiringPiSetup () == -1) return 1;
|
||||||
|
printf("sending code[%i]\n", code);
|
||||||
|
RCSwitch mySwitch = RCSwitch();
|
||||||
|
if (protocol != 0) mySwitch.setProtocol(protocol);
|
||||||
|
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
|
||||||
|
mySwitch.enableTransmit(PIN);
|
||||||
|
|
||||||
|
mySwitch.send(code, length);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
# Please take the time to finish this file as described in
|
||||||
|
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
|
||||||
|
# and make it available to others by sending it to
|
||||||
|
# <lirc@bartelmus.de>
|
||||||
|
#
|
||||||
|
# This config file was automatically generated
|
||||||
|
# using lirc-0.10.1(default) on Sat Jun 1 16:13:39 2024
|
||||||
|
# Command line used: --disable-namespace -f -d /dev/lirc0
|
||||||
|
# Kernel version (uname -r): 6.6.31+rpt-rpi-v8
|
||||||
|
#
|
||||||
|
# Remote name (as of config file): Teufel
|
||||||
|
# Brand of remote device, the thing you hold in your hand:
|
||||||
|
# Remote device model nr:
|
||||||
|
# Remote device info url:
|
||||||
|
# Does remote device has a bundled capture device e. g., a
|
||||||
|
# usb dongle? :
|
||||||
|
# For bundled USB devices: usb vendor id, product id
|
||||||
|
# and device string (use dmesg or lsusb):
|
||||||
|
# Type of device controlled
|
||||||
|
# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :
|
||||||
|
# Device(s) controlled by this remote:
|
||||||
|
|
||||||
|
begin remote
|
||||||
|
|
||||||
|
name Teufel
|
||||||
|
flags RAW_CODES|CONST_LENGTH
|
||||||
|
eps 30
|
||||||
|
aeps 100
|
||||||
|
|
||||||
|
gap 107901
|
||||||
|
|
||||||
|
begin raw_codes
|
||||||
|
|
||||||
|
name PowerOn
|
||||||
|
9051 2199 600
|
||||||
|
|
||||||
|
name Optical1
|
||||||
|
9050 2199 601
|
||||||
|
|
||||||
|
name aux
|
||||||
|
9048 2200 599
|
||||||
|
|
||||||
|
end raw_codes
|
||||||
|
|
||||||
|
end remote
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[[protocols]]
|
||||||
|
name = "TeufelRemote"
|
||||||
|
protocol = "nec"
|
||||||
|
variant = "nec"
|
||||||
|
[protocols.scancodes]
|
||||||
|
0x10a = "PowerOn"
|
||||||
|
0x106 = "Optical1"
|
||||||
|
0x102 = "aux"
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
Screen Down:
|
||||||
|
rpi-rf_send -g 27 -t 3 -p 136 83716
|
||||||
|
Screen Up:
|
||||||
|
rpi-rf_send -g 27 -t 3 -p 136 83713
|
||||||
|
Screen Middle
|
||||||
|
rpi-rf_send -g 27 -t 3 -p 136 83714
|
||||||
|
|
||||||
|
Relais ON
|
||||||
|
rpi-rf_send -g 27 -t 2 958927872 -p 691
|
||||||
|
Relais OFF
|
||||||
|
rpi-rf_send -g 27 -t 2 891819008 -p 691
|
||||||
|
|
||||||
|
IR
|
||||||
|
irsend LIST remote_led ""
|
||||||
|
irsend LIST Teufel_devinput ""
|
||||||
|
irsend LIST beamer_devinput ""
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
|||||||
|
#import the GPIO and time package
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
GPIO.setmode(GPIO.BOARD)
|
||||||
|
led_pin_board=16
|
||||||
|
led_pin_bcm="GPIO23"
|
||||||
|
GPIO.setup(led_pin_board, GPIO.OUT)
|
||||||
|
# loop through 50 times, on/off for 1 second
|
||||||
|
for i in range(50):
|
||||||
|
print("Flash")
|
||||||
|
GPIO.output(led_pin_board,True)
|
||||||
|
time.sleep(1)
|
||||||
|
GPIO.output(led_pin_board,False)
|
||||||
|
time.sleep(1)
|
||||||
|
GPIO.cleanup()
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[[protocols]]
|
||||||
|
name = "led_remote"
|
||||||
|
protocol = "nec"
|
||||||
|
variant = "nec"
|
||||||
|
[protocols.scancodes]
|
||||||
|
0x40 = "PowerOn"
|
||||||
|
0x41 = "PowerOff"
|
||||||
|
0x58 = "Red"
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
from rpi_rf import RFDevice
|
||||||
|
import logging
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
MQTT_BROKER_HOST = "homeassistant"
|
||||||
|
MQTT_BROKER_PORT = 1883
|
||||||
|
MQTT_USERNAME = "MQTTBrokerUser"
|
||||||
|
MQTT_PASSWORD = "mqtt1510##"
|
||||||
|
MQTT_TOPIC = "serverhost_torrent_sensor/topic" # Set the desired topic
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S',
|
||||||
|
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s',)
|
||||||
|
|
||||||
|
# The callback for when the client receives a CONNACK response from the server.
|
||||||
|
def on_connect(client, userdata, flags, reason_code, properties):
|
||||||
|
logging.info(f"Connected with result code {reason_code}")
|
||||||
|
# Subscribing in on_connect() means that if we lose the connection and
|
||||||
|
# reconnect then subscriptions will be renewed.
|
||||||
|
client.subscribe("home/livingroom/raspi/screen")
|
||||||
|
client.subscribe("home/livingroom/raspi/beamer")
|
||||||
|
client.subscribe("home/livingroom/raspi/teufelaudio")
|
||||||
|
|
||||||
|
msg_info = client.publish("home/livingroom/raspi/available", "online", qos=1, retain=True)
|
||||||
|
# Our application produce some messages
|
||||||
|
|
||||||
|
# The callback for when a PUBLISH message is received from the server.
|
||||||
|
def on_message(client, userdata, msg):
|
||||||
|
timeout=5
|
||||||
|
if "screen down" in str(msg.payload):
|
||||||
|
logging.info("Lowering Screen")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
# Lower Screen via RFdevice
|
||||||
|
code=83716
|
||||||
|
protocol=3
|
||||||
|
pulselength=136
|
||||||
|
length=None
|
||||||
|
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||||
|
time.sleep(0.2)
|
||||||
|
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||||
|
if "screen up" in str(msg.payload):
|
||||||
|
logging.info("Raising Screen")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
# Lower Screen via RFdevice
|
||||||
|
code=83713
|
||||||
|
protocol=3
|
||||||
|
pulselength=136
|
||||||
|
length=None
|
||||||
|
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||||
|
time.sleep(0.2)
|
||||||
|
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||||
|
|
||||||
|
if "teufel power" in str(msg.payload):
|
||||||
|
logging.info("Send ON/OFF to Teufel Audio")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once teufel_nf power"
|
||||||
|
try:
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
print("Command returned %s, %s"%(returned_output,e))
|
||||||
|
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||||
|
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
if "teufel opt1" in str(msg.payload) or "teufel aux" in str(msg.payload):
|
||||||
|
time.sleep(10)
|
||||||
|
if "teufel opt1" in str(msg.payload):
|
||||||
|
logging.info("Send Opt1 to Teufel Audio")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once teufel_nf opt1"
|
||||||
|
try:
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
print("Command returned %s, %s"%(returned_output,e))
|
||||||
|
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||||
|
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
if "teufel aux" in str(msg.payload):
|
||||||
|
logging.info("Send aux to Teufel Audio")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once teufel_nf aux"
|
||||||
|
try:
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
print("Command returned %s, %s"%(returned_output,e))
|
||||||
|
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||||
|
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
if "teufel Mute" in str(msg.payload):
|
||||||
|
logging.info("Send Mute to Teufel Audio")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once teufel_nf Mute"
|
||||||
|
try:
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
print("Command returned %s, %s"%(returned_output,e))
|
||||||
|
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
|
||||||
|
if "teufel VolUp" in str(msg.payload):
|
||||||
|
logging.info("Send VolUp to Teufel Audio")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once teufel_nf VolUp"
|
||||||
|
for i in range(5):
|
||||||
|
try:
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
print("Command returned %s, %s"%(returned_output,e))
|
||||||
|
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||||
|
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if "teufel VolDown" in str(msg.payload):
|
||||||
|
logging.info("Send VolDown to Teufel Audio")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once teufel_nf VolDown"
|
||||||
|
for i in range(5):
|
||||||
|
try:
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
print("Command returned %s, %s"%(returned_output,e))
|
||||||
|
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||||
|
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if "beamer off" in str(msg.payload):
|
||||||
|
logging.info("Send Off to Beamer")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once beamer_optoma poweroff"
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
time.sleep(1)
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
if "beamer on" in str(msg.payload):
|
||||||
|
logging.info("Send On to Beamer")
|
||||||
|
logging.debug(msg.payload)
|
||||||
|
cmd="irsend send_once beamer_optoma poweron"
|
||||||
|
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||||
|
logging.info("Ret: " + str(returned_output))
|
||||||
|
def on_subscribe(client, userdata, mid, reason_code_list, properties):
|
||||||
|
# Since we subscribed only for a single channel, reason_code_list contains
|
||||||
|
# a single entry
|
||||||
|
if reason_code_list[0].is_failure:
|
||||||
|
logging.debug(f"Broker rejected you subscription: {reason_code_list[0]}")
|
||||||
|
else:
|
||||||
|
logging.info(f"Broker granted the following QoS: {reason_code_list[0].value}")
|
||||||
|
|
||||||
|
def on_unsubscribe(client, userdata, mid, reason_code_list, properties):
|
||||||
|
# Be careful, the reason_code_list is only present in MQTTv5.
|
||||||
|
# In MQTTv3 it will always be empty
|
||||||
|
if len(reason_code_list) == 0 or not reason_code_list[0].is_failure:
|
||||||
|
logging.debug("unsubscribe succeeded (if SUBACK is received in MQTTv3 it success)")
|
||||||
|
else:
|
||||||
|
logging.info(f"Broker replied with failure: {reason_code_list[0]}")
|
||||||
|
client.disconnect()
|
||||||
|
|
||||||
|
## RX Init
|
||||||
|
print("Starting")
|
||||||
|
gpio_port_board=27
|
||||||
|
rfdevice = RFDevice(gpio_port_board)
|
||||||
|
rfdevice.enable_tx()
|
||||||
|
rfdevice.tx_repeat = 10
|
||||||
|
|
||||||
|
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||||
|
|
||||||
|
mqttc.on_connect = on_connect
|
||||||
|
mqttc.on_message = on_message
|
||||||
|
|
||||||
|
mqttc.on_subscribe = on_subscribe
|
||||||
|
mqttc.on_unsubscribe = on_unsubscribe
|
||||||
|
unacked_publish = set()
|
||||||
|
|
||||||
|
# Set username and password for authentication
|
||||||
|
mqttc.username_pw_set(username=MQTT_USERNAME, password=MQTT_PASSWORD)
|
||||||
|
|
||||||
|
# Connect to the MQTT broker
|
||||||
|
mqttc.connect(MQTT_BROKER_HOST, MQTT_BROKER_PORT, 60)
|
||||||
|
|
||||||
|
mqttc.loop_start()
|
||||||
|
|
||||||
|
|
||||||
|
msg_info2 = mqttc.publish("sensor/test", "6", qos=1)
|
||||||
|
unacked_publish.add(msg_info2.mid)
|
||||||
|
|
||||||
|
# Wait for all message to be published
|
||||||
|
while len(unacked_publish):
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# Due to race-condition described above, the following way to wait for all publish is safer
|
||||||
|
msg_info2.wait_for_publish()
|
||||||
|
|
||||||
|
mqttc.disconnect()
|
||||||
|
mqttc.loop_stop()
|
||||||
|
|
||||||
|
rfdevice.cleanup()
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Raspberry MQTT Service
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/home/lucas/paho-mqtt/bin/python /home/lucas/scripts/raspberry/python/mqtt_client.py
|
||||||
|
WorkingDirectory=/home/lucas/scripts/raspberry/python/
|
||||||
|
StandardOutput=inherit
|
||||||
|
StandardError=inherit
|
||||||
|
Restart=always
|
||||||
|
User=lucas
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from rpi_rf import RFDevice
|
||||||
|
|
||||||
|
rfdevice = None
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def exithandler(signal, frame):
|
||||||
|
rfdevice.cleanup()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
|
||||||
|
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
|
||||||
|
parser.add_argument('-g', dest='gpio', type=int, default=27,
|
||||||
|
help="GPIO pin (Default: 27)")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, exithandler)
|
||||||
|
rfdevice = RFDevice(args.gpio)
|
||||||
|
rfdevice.enable_rx()
|
||||||
|
timestamp = None
|
||||||
|
logging.info("Listening for codes on GPIO " + str(args.gpio))
|
||||||
|
while True:
|
||||||
|
if rfdevice.rx_code_timestamp != timestamp:
|
||||||
|
timestamp = rfdevice.rx_code_timestamp
|
||||||
|
logging.info(str(rfdevice.rx_code) +
|
||||||
|
" [pulselength " + str(rfdevice.rx_pulselength) +
|
||||||
|
", protocol " + str(rfdevice.rx_proto) + "]")
|
||||||
|
time.sleep(0.01)
|
||||||
|
rfdevice.cleanup()
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from RPi import GPIO
|
||||||
|
import time, argparse
|
||||||
|
import numpy as np
|
||||||
|
parser = argparse.ArgumentParser(description='Analyze RF signal for Nexa codes')
|
||||||
|
parser.add_argument('-g', dest='gpio', type=int, default=27, help='GPIO pin (Default: 27)')
|
||||||
|
parser.add_argument('-s', dest='secs', type=int, default=3, help='Seconds to record (Default: 3)')
|
||||||
|
parser.add_argument('--raw', dest='raw', action='store_true', default=False, help='Output raw samples')
|
||||||
|
parser.add_argument('-f', dest='file',default="data.npy", help='Data file (Default: data.npy)')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
times = []
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(args.gpio, GPIO.IN)
|
||||||
|
GPIO.add_event_detect(args.gpio, GPIO.BOTH,
|
||||||
|
callback=lambda ch: times.append(time.perf_counter_ns()//1000))
|
||||||
|
|
||||||
|
time.sleep(args.secs)
|
||||||
|
GPIO.remove_event_detect(args.gpio)
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
|
# Calculate difference between consecutive times
|
||||||
|
diff = [b-a for a,b in zip(times, times[1:])]
|
||||||
|
|
||||||
|
|
||||||
|
np.save(args.file, diff)
|
||||||
|
if args.raw: # Print a raw dump
|
||||||
|
for d in diff: print(d, end='\n' if d>5e3 else ' ')
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
"""
|
||||||
|
Script Name: ir-keytable-record.py
|
||||||
|
Purpose: Script to capture remote control key presses and generate a TOML file.
|
||||||
|
Author: Vince Ricosti
|
||||||
|
Url: https://raw.githubusercontent.com/vricosti/infrared-resources/main/ir-keytable-record.py
|
||||||
|
Usage:
|
||||||
|
Run the script with -h or --help to see usage options.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
import signal
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
def get_ir_keytable_output(sysdev):
|
||||||
|
cmd = ["stdbuf", "-oL", "ir-keytable", "-s", sysdev, "-t"]
|
||||||
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, universal_newlines=True)
|
||||||
|
|
||||||
|
lines = []
|
||||||
|
for line in iter(process.stdout.readline, ''):
|
||||||
|
lines.append(line)
|
||||||
|
if "lirc protocol" in line:
|
||||||
|
break
|
||||||
|
|
||||||
|
process.send_signal(signal.SIGINT)
|
||||||
|
process.communicate()
|
||||||
|
|
||||||
|
return ''.join(lines)
|
||||||
|
|
||||||
|
def extract_protocol_and_scancode(output):
|
||||||
|
# Extract lines containing "lirc protocol"
|
||||||
|
match = re.search(r"lirc protocol\(([^)]+)\): scancode = (0x[\da-fA-F]+)", output)
|
||||||
|
if match:
|
||||||
|
protocol, scancode = match.groups()
|
||||||
|
return protocol, scancode
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
def parse_arguments():
|
||||||
|
parser = argparse.ArgumentParser(description='Script to capture remote control key presses and generate a TOML file.')
|
||||||
|
parser.add_argument('-s', '--sysdev', default='rc0', help='RC device to control. Defaults to rc0 if not specified.')
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parse_arguments()
|
||||||
|
sysdev = args.sysdev
|
||||||
|
|
||||||
|
filename = input("Please enter the file name: ").strip()
|
||||||
|
filename_no_ext, ext = os.path.splitext(filename)
|
||||||
|
if not ext:
|
||||||
|
filename = f"{filename}.toml"
|
||||||
|
|
||||||
|
keys_dict = {}
|
||||||
|
global_protocol = None
|
||||||
|
|
||||||
|
while True:
|
||||||
|
key_name = input("Enter the key name (in upper case) or a space to stop: ").strip()
|
||||||
|
if key_name == '':
|
||||||
|
break
|
||||||
|
|
||||||
|
#print("Please press the button on your remote for key:", key_name)
|
||||||
|
output = get_ir_keytable_output(sysdev)
|
||||||
|
protocol, scancode = extract_protocol_and_scancode(output)
|
||||||
|
if protocol and scancode:
|
||||||
|
print(f'{scancode} = "{key_name}" #protocol ="{protocol}"')
|
||||||
|
keys_dict[key_name] = scancode
|
||||||
|
if not global_protocol:
|
||||||
|
global_protocol = protocol
|
||||||
|
if global_protocol == 'rc5x_20':
|
||||||
|
global_protocol = 'rc5'
|
||||||
|
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
f.write("[[protocols]]\n")
|
||||||
|
f.write(f'name = "{filename_no_ext}"\n')
|
||||||
|
f.write(f'protocol = "{global_protocol}"\n')
|
||||||
|
f.write(f'variant = "{global_protocol}"\n')
|
||||||
|
f.write("[protocols.scancodes]\n")
|
||||||
|
for key_name, scancode in keys_dict.items():
|
||||||
|
f.write(f'{scancode} = "{key_name}"\n')
|
||||||
|
|
||||||
|
print(f"File '{filename}' has been written.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
# for GPIO numbering, choose BCM
|
||||||
|
#GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
|
# or, for pin numbering, choose BOARD
|
||||||
|
GPIO.setmode(GPIO.BOARD)
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BOARD) # sets numbering system of GPIO pins
|
||||||
|
channel1 = 15 # Replace MY_BOARD_PIN_ID with your actual pin number
|
||||||
|
channel2 = 16 # Replace MY_BOARD_PIN_ID with your actual pin number
|
||||||
|
|
||||||
|
GPIO.setup(channel1, GPIO.IN) # set the GPIO pin as an input
|
||||||
|
GPIO.setup(channel2, GPIO.IN) # set the GPIO pin as an input
|
||||||
|
|
||||||
|
# then some code where you read the input as many times as needed:
|
||||||
|
while(True):
|
||||||
|
value1 = GPIO.input(channel1)
|
||||||
|
value2 = GPIO.input(channel2)
|
||||||
|
print("1:%d\n"%value1)
|
||||||
|
print("2:%d\n"%value2)
|
||||||
|
time.sleep(0.5)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
printf "Wrong Usage:\n1...Pin Number\n2...set/reset\n3...0/1\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
printf "Pin: $1\nMode: $2\nValue: $3\n"
|
||||||
|
pin=$1
|
||||||
|
#choose Pin $pin
|
||||||
|
if [ "$2" == "reset" ]; then
|
||||||
|
#reset Pin 17
|
||||||
|
printf "Reset Pin $pin\n"
|
||||||
|
echo "$pin" > /sys/class/gpio/unexport
|
||||||
|
elif [ "$2" == "set" ]; then
|
||||||
|
if [ $# -ne 3 ]; then
|
||||||
|
printf "Set Pin requires: PinNumber, Set, Value\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "$pin" > /sys/class/gpio/export
|
||||||
|
#set direction of GPIO Pin
|
||||||
|
echo "out" > /sys/class/gpio/gpio$pin/direction
|
||||||
|
#set Value of GPIO Pin (0,1)
|
||||||
|
echo "$3" > /sys/class/gpio/gpio$pin/value
|
||||||
|
fi
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$1" != "wlan0" ] && [ "$1" != "eth0" ]; then
|
||||||
|
printf "Wrong Interface, \$1 must be eth0 or wlan0\n";
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$(whoami)" != "root" ]; then
|
||||||
|
printf "Script must be executed as root\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$(/sbin/ifconfig | grep eth0)" != "" ]; then
|
||||||
|
ifdown eth0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(/sbin/ifconfig | grep wlan0)" != "" ]; then
|
||||||
|
ifdown wlan0
|
||||||
|
fi
|
||||||
|
cp /etc/network/interfaces.$1 /etc/network/interfaces
|
||||||
|
ifup $1
|
||||||
|
/sbin/ifconfig
|
||||||
|
printf "Network interface has been changed to %s\n" "$1"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$(ps -e | grep recieve)" != "" ];then
|
||||||
|
ps -e | grep recieve && tail -n 6 $(ls /home/lucas/.LOG/MS* | tail -n1)
|
||||||
|
else
|
||||||
|
printf "recieveMS inactive\n"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
awk '{s=0;for(i=1;i<=NF;i++) s+=$i;print s}' <<< "1 2 3"
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
hostname=$1
|
||||||
|
|
||||||
|
expect <<'EOF'
|
||||||
|
set target=$hostname
|
||||||
|
spawn ssh lucas@$target
|
||||||
|
set count 0
|
||||||
|
expect {
|
||||||
|
timeout {puts "timeout happened"}
|
||||||
|
eof {puts "eof received"}
|
||||||
|
"$ " {send "sudo /sbin/shutdown -P 0i\r";exp_continue}
|
||||||
|
"Permission denied" {incr count;exp_continue}
|
||||||
|
}
|
||||||
|
|
||||||
|
set results $expect_out(buffer)
|
||||||
|
|
||||||
|
if {[regexp -nocase "Shutdown scheduled" $results]} {
|
||||||
|
puts "[index $argv 0] has been shut down"
|
||||||
|
} else {
|
||||||
|
puts "Failed"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
NETIF=$1
|
||||||
|
if [ "$1" != "eth0" ] && [ "$1" != "all" ] && [ "$1" != "wlan0" ] && [ "$1" != "bond0" ] && [ "$1" != "IF" ]; then
|
||||||
|
printf "Wrong NETIF: $NETIF\neth0, wlan0 or all\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$1" == "all" ] || [ "$1" == "bond0" ] || [ "$1" == "IF" ]; then
|
||||||
|
NETIF="eth0"
|
||||||
|
fi
|
||||||
|
if [ "$1" == "wlan0" ] || [ "$1" == "all" ] || [ "$1" == "bond0" ] || [ "$1" == "IF" ]; then
|
||||||
|
echo "wlan power & txpower on"
|
||||||
|
iwconfig wlan0 power on
|
||||||
|
iwconfig wlan0 txpower auto
|
||||||
|
if [ "$(ifconfig | grep wlan0)" == "" ]; then
|
||||||
|
ifup wlan0
|
||||||
|
fi
|
||||||
|
elif [ "$1" == "eth0" ]; then
|
||||||
|
echo "wlan power & txpower off"
|
||||||
|
if [ "$(ifconfig | grep wlan0)" != "" ]; then
|
||||||
|
sudo ifdown wlan0
|
||||||
|
fi
|
||||||
|
iwconfig wlan0 txpower off
|
||||||
|
iwconfig wlan0 power off
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo Flush existing rules
|
||||||
|
ufw disable
|
||||||
|
|
||||||
|
echo Flush
|
||||||
|
iptables -F
|
||||||
|
|
||||||
|
echo Delete
|
||||||
|
iptables -X
|
||||||
|
|
||||||
|
echo Make Rules
|
||||||
|
|
||||||
|
echo Allen verkehr blockieren
|
||||||
|
iptables -P INPUT DROP
|
||||||
|
iptables -P FORWARD DROP
|
||||||
|
iptables -P OUTPUT ACCEPT
|
||||||
|
|
||||||
|
echo loopback $NETIF
|
||||||
|
iptables -A INPUT -i lo -s 127.0.0.1 -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o lo -j ACCEPT
|
||||||
|
|
||||||
|
for i in 1 2 3
|
||||||
|
do
|
||||||
|
|
||||||
|
echo Datenverkehr akzeptieren der zu einer bereits geoeffneten Verbindung gehoert $NETIF
|
||||||
|
iptables -A INPUT -i $NETIF -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
#if [ "$NETIF" != "bond0" ]; then
|
||||||
|
echo Incoming SSH p1160 $NETIF
|
||||||
|
iptables -A INPUT -i $NETIF -p tcp -m state --state NEW -m tcp --dport 1160 -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o $NETIF -p tcp --sport 1160 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
#else
|
||||||
|
#echo Reject Incoming SSH p1160 $NETIF
|
||||||
|
#iptables -A INPUT -i $NETIF -p tcp -m state --state NEW -m tcp --dport 1160 -j REJECT
|
||||||
|
#iptables -A OUTPUT -o $NETIF -p tcp --sport 1160 -m state --state ESTABLISHED -j REJECT
|
||||||
|
#fi
|
||||||
|
#echo Outgoing SSh P1160 $NETIF
|
||||||
|
#iptables -A OUTPUT -o $NETIF -p tcp --dport 1160 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||||
|
#iptables -A INPUT -i $NETIF -p tcp --sport 1160 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
|
||||||
|
#echo Outgoing SSH p3032 $NETIF
|
||||||
|
#iptables -A OUTPUT -o $NETIF -p tcp --dport 3032 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||||
|
#iptables -A INPUT -i $NETIF -p tcp --sport 3032 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
|
||||||
|
#echo Updates - Outgoing Network Traffic $NETIF
|
||||||
|
#iptables -A OUTPUT -o $NETIF -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||||||
|
#iptables -A OUTPUT -o $NETIF -p tcp --dport 80 -m state --state NEW -j ACCEPT
|
||||||
|
#iptables -A OUTPUT -o $NETIF -p tcp --dport 53 -m state --state NEW -j ACCEPT
|
||||||
|
#iptables -A OUTPUT -o $NETIF -p udp --dport 53 -m state --state NEW -j ACCEPT
|
||||||
|
|
||||||
|
echo Ping $NETIF
|
||||||
|
iptables -A INPUT -i $NETIF -p icmp --icmp-type echo-request -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o $NETIF -p icmp --icmp-type echo-reply -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o $NETIF -p icmp --icmp-type echo-request -j ACCEPT
|
||||||
|
iptables -A INPUT -i $NETIF -p icmp --icmp-type echo-reply -j ACCEPT
|
||||||
|
|
||||||
|
if [ "$1" == "IF" ] || [ "$1" == "all" ] || [ "$1" == "bond0" ] && [ $i -eq 1 ]; then
|
||||||
|
NETIF="wlan0"
|
||||||
|
elif [ "$1" == "bond0" ] && [ $i -eq 2 ]; then
|
||||||
|
NETIF="bond0"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo Logging
|
||||||
|
iptables -N LOGGING
|
||||||
|
iptables -A INPUT -j LOGGING
|
||||||
|
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7
|
||||||
|
iptables -A LOGGING -j DROP
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,541 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
function color (){
|
||||||
|
echo "\e[$1m$2\e[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
function extend (){
|
||||||
|
local str="$1"
|
||||||
|
let spaces=60-${#1}
|
||||||
|
while [ $spaces -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spaces=spaces-1
|
||||||
|
done
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function center (){
|
||||||
|
local str="$1"
|
||||||
|
let spacesLeft=(78-${#1})/2
|
||||||
|
let spacesRight=78-spacesLeft-${#1}
|
||||||
|
while [ $spacesLeft -gt 0 ]; do
|
||||||
|
str=" $str"
|
||||||
|
let spacesLeft=spacesLeft-1
|
||||||
|
done
|
||||||
|
|
||||||
|
while [ $spacesRight -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spacesRight=spacesRight-1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function sec2time (){
|
||||||
|
local input=$1
|
||||||
|
|
||||||
|
if [ $input -lt 60 ]; then
|
||||||
|
echo "$input seconds"
|
||||||
|
else
|
||||||
|
((days=input/86400))
|
||||||
|
((input=input%86400))
|
||||||
|
((hours=input/3600))
|
||||||
|
((input=input%3600))
|
||||||
|
((mins=input/60))
|
||||||
|
|
||||||
|
local daysPlural="s"
|
||||||
|
local hoursPlural="s"
|
||||||
|
local minsPlural="s"
|
||||||
|
|
||||||
|
if [ $days -eq 1 ]; then
|
||||||
|
daysPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $hours -eq 1 ]; then
|
||||||
|
hoursPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $mins -eq 1 ]; then
|
||||||
|
minsPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$days day$daysPlural, $hours hour$hoursPlural, $mins minute$minsPlural"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
borderColor=35
|
||||||
|
headerLeafColor=32
|
||||||
|
headerRaspberryColor=31
|
||||||
|
greetingsColor=36
|
||||||
|
statsLabelColor=33
|
||||||
|
|
||||||
|
borderLine="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
borderTopLine=$(color $borderColor "┏$borderLine┓")
|
||||||
|
borderBottomLine=$(color $borderColor "┗$borderLine┛")
|
||||||
|
borderBar=$(color $borderColor "┃")
|
||||||
|
borderEmptyLine="$borderBar $borderBar"
|
||||||
|
|
||||||
|
# Header
|
||||||
|
header="$borderTopLine\n$borderEmptyLine\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " .~~. .~~. ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " '. \ ' ' / .' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " .~ .~~~..~. _ _ ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " : .~.'~'.~. : ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ ( ) ( ) ~ | _| .'|_ -| . | . | -_| _| _| | | | . | | ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~'.~.'~' : ) |_| |__,|___| _|___|___|_| |_| |_ | | _|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ .~ ( ) ~. ~ |_| |___| |_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~' : ) ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~ .~~~. ~' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~' ")$borderBar"
|
||||||
|
|
||||||
|
me=$(whoami)
|
||||||
|
|
||||||
|
# Greetings
|
||||||
|
greetings="$borderBar$(color $greetingsColor "$(center "Welcome back, $me!")")$borderBar\n"
|
||||||
|
greetings="$greetings$borderBar$(color $greetingsColor "$(center "$(date +"%A, %d %B %Y, %T")")")$borderBar"
|
||||||
|
|
||||||
|
# System information
|
||||||
|
read loginFrom loginIP loginDate <<< $(last $me --time-format iso -2 | awk 'NR==2 { print $2,$3,$4 }')
|
||||||
|
|
||||||
|
# TTY login
|
||||||
|
if [[ $loginDate == - ]]; then
|
||||||
|
loginDate=$loginIP
|
||||||
|
loginIP=$loginFrom
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $loginDate == *T* ]]; then
|
||||||
|
login="$(date -d $loginDate +"%A, %d %B %Y, %T") ($loginIP)"
|
||||||
|
else
|
||||||
|
# Not enough logins
|
||||||
|
login="None"
|
||||||
|
fi
|
||||||
|
|
||||||
|
label1="$(extend "$login")"
|
||||||
|
label1="$borderBar $(color $statsLabelColor "Last Login....:") $label1$borderBar"
|
||||||
|
|
||||||
|
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
|
||||||
|
uptime="$uptime ($(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%d-%m-%Y %H:%M:%S"))"
|
||||||
|
|
||||||
|
label2="$(extend "$uptime")"
|
||||||
|
label2="$borderBar $(color $statsLabelColor "Uptime........:") $label2$borderBar"
|
||||||
|
|
||||||
|
label3="$(extend "$(free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }')")"
|
||||||
|
label3="$borderBar $(color $statsLabelColor "Memory........:") $label3$borderBar"
|
||||||
|
|
||||||
|
label4="$(extend "$(df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }')")"
|
||||||
|
label4="$borderBar $(color $statsLabelColor "Home space....:") $label4$borderBar"
|
||||||
|
|
||||||
|
label5="$(extend "$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9")ºC")"
|
||||||
|
label5="$borderBar $(color $statsLabelColor "Temperature...:") $label5$borderBar"
|
||||||
|
|
||||||
|
stats="$label1\n$label2\n$label3\n$label4\n$label5"
|
||||||
|
|
||||||
|
# Print motd
|
||||||
|
echo -e "$header\n$borderEmptyLine\n$greetings\n$borderEmptyLine\n$stats\n$borderEmptyLine\n$borderBottomLine" #!/bin/bash
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
function color (){
|
||||||
|
echo "\e[$1m$2\e[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
function extend (){
|
||||||
|
local str="$1"
|
||||||
|
let spaces=60-${#1}
|
||||||
|
while [ $spaces -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spaces=spaces-1
|
||||||
|
done
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function center (){
|
||||||
|
local str="$1"
|
||||||
|
let spacesLeft=(78-${#1})/2
|
||||||
|
let spacesRight=78-spacesLeft-${#1}
|
||||||
|
while [ $spacesLeft -gt 0 ]; do
|
||||||
|
str=" $str"
|
||||||
|
let spacesLeft=spacesLeft-1
|
||||||
|
done
|
||||||
|
|
||||||
|
while [ $spacesRight -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spacesRight=spacesRight-1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function sec2time (){
|
||||||
|
local input=$1
|
||||||
|
|
||||||
|
if [ $input -lt 60 ]; then
|
||||||
|
echo "$input seconds"
|
||||||
|
else
|
||||||
|
((days=input/86400))
|
||||||
|
((input=input%86400))
|
||||||
|
((hours=input/3600))
|
||||||
|
((input=input%3600))
|
||||||
|
((mins=input/60))
|
||||||
|
|
||||||
|
local daysPlural="s"
|
||||||
|
local hoursPlural="s"
|
||||||
|
local minsPlural="s"
|
||||||
|
|
||||||
|
if [ $days -eq 1 ]; then
|
||||||
|
daysPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $hours -eq 1 ]; then
|
||||||
|
hoursPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $mins -eq 1 ]; then
|
||||||
|
minsPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$days day$daysPlural, $hours hour$hoursPlural, $mins minute$minsPlural"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
borderColor=35
|
||||||
|
headerLeafColor=32
|
||||||
|
headerRaspberryColor=31
|
||||||
|
greetingsColor=36
|
||||||
|
statsLabelColor=33
|
||||||
|
|
||||||
|
borderLine="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
borderTopLine=$(color $borderColor "┏$borderLine┓")
|
||||||
|
borderBottomLine=$(color $borderColor "┗$borderLine┛")
|
||||||
|
borderBar=$(color $borderColor "┃")
|
||||||
|
borderEmptyLine="$borderBar $borderBar"
|
||||||
|
|
||||||
|
# Header
|
||||||
|
header="$borderTopLine\n$borderEmptyLine\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " .~~. .~~. ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " '. \ ' ' / .' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " .~ .~~~..~. _ _ ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " : .~.'~'.~. : ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ ( ) ( ) ~ | _| .'|_ -| . | . | -_| _| _| | | | . | | ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~'.~.'~' : ) |_| |__,|___| _|___|___|_| |_| |_ | | _|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ .~ ( ) ~. ~ |_| |___| |_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~' : ) ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~ .~~~. ~' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~' ")$borderBar"
|
||||||
|
|
||||||
|
me=$(whoami)
|
||||||
|
|
||||||
|
# Greetings
|
||||||
|
greetings="$borderBar$(color $greetingsColor "$(center "Welcome back, $me!")")$borderBar\n"
|
||||||
|
greetings="$greetings$borderBar$(color $greetingsColor "$(center "$(date +"%A, %d %B %Y, %T")")")$borderBar"
|
||||||
|
|
||||||
|
# System information
|
||||||
|
read loginFrom loginIP loginDate <<< $(last $me --time-format iso 2 | awk 'NR==2 { print $2,$3,$4 }')
|
||||||
|
|
||||||
|
# TTY login
|
||||||
|
if [[ $loginDate == - ]]; then
|
||||||
|
loginDate=$loginIP
|
||||||
|
loginIP=$loginFrom
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $loginDate == *T* ]]; then
|
||||||
|
login="$(date -d $loginDate +"%A, %d %B %Y, %T") ($loginIP)"
|
||||||
|
else
|
||||||
|
# Not enough logins
|
||||||
|
login="None"
|
||||||
|
fi
|
||||||
|
|
||||||
|
label1="$(extend "$login")"
|
||||||
|
label1="$borderBar $(color $statsLabelColor "Last Login....:") $label1$borderBar"
|
||||||
|
|
||||||
|
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
|
||||||
|
uptime="$uptime ($(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%d-%m-%Y %H:%M:%S"))"
|
||||||
|
|
||||||
|
label2="$(extend "$uptime")"
|
||||||
|
label2="$borderBar $(color $statsLabelColor "Uptime........:") $label2$borderBar"
|
||||||
|
|
||||||
|
label3="$(extend "$(free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }')")"
|
||||||
|
label3="$borderBar $(color $statsLabelColor "Memory........:") $label3$borderBar"
|
||||||
|
|
||||||
|
label4="$(extend "$(df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }')")"
|
||||||
|
label4="$borderBar $(color $statsLabelColor "Home space....:") $label4$borderBar"
|
||||||
|
|
||||||
|
label5="$(extend "$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9")ºC")"
|
||||||
|
label5="$borderBar $(color $statsLabelColor "Temperature...:") $label5$borderBar"
|
||||||
|
|
||||||
|
stats="$label1\n$label2\n$label3\n$label4\n$label5"
|
||||||
|
|
||||||
|
# Print motd
|
||||||
|
echo -e "$header\n$borderEmptyLine\n$greetings\n$borderEmptyLine\n$stats\n$borderEmptyLine\n$borderBottomLine" #!/bin/bash
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
function color (){
|
||||||
|
echo "\e[$1m$2\e[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
function extend (){
|
||||||
|
local str="$1"
|
||||||
|
let spaces=60-${#1}
|
||||||
|
while [ $spaces -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spaces=spaces-1
|
||||||
|
done
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function center (){
|
||||||
|
local str="$1"
|
||||||
|
let spacesLeft=(78-${#1})/2
|
||||||
|
let spacesRight=78-spacesLeft-${#1}
|
||||||
|
while [ $spacesLeft -gt 0 ]; do
|
||||||
|
str=" $str"
|
||||||
|
let spacesLeft=spacesLeft-1
|
||||||
|
done
|
||||||
|
|
||||||
|
while [ $spacesRight -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spacesRight=spacesRight-1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function sec2time (){
|
||||||
|
local input=$1
|
||||||
|
|
||||||
|
if [ $input -lt 60 ]; then
|
||||||
|
echo "$input seconds"
|
||||||
|
else
|
||||||
|
((days=input/86400))
|
||||||
|
((input=input%86400))
|
||||||
|
((hours=input/3600))
|
||||||
|
((input=input%3600))
|
||||||
|
((mins=input/60))
|
||||||
|
|
||||||
|
local daysPlural="s"
|
||||||
|
local hoursPlural="s"
|
||||||
|
local minsPlural="s"
|
||||||
|
|
||||||
|
if [ $days -eq 1 ]; then
|
||||||
|
daysPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $hours -eq 1 ]; then
|
||||||
|
hoursPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $mins -eq 1 ]; then
|
||||||
|
minsPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$days day$daysPlural, $hours hour$hoursPlural, $mins minute$minsPlural"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
borderColor=35
|
||||||
|
headerLeafColor=32
|
||||||
|
headerRaspberryColor=31
|
||||||
|
greetingsColor=36
|
||||||
|
statsLabelColor=33
|
||||||
|
|
||||||
|
borderLine="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
borderTopLine=$(color $borderColor "┏$borderLine┓")
|
||||||
|
borderBottomLine=$(color $borderColor "┗$borderLine┛")
|
||||||
|
borderBar=$(color $borderColor "┃")
|
||||||
|
borderEmptyLine="$borderBar $borderBar"
|
||||||
|
|
||||||
|
# Header
|
||||||
|
header="$borderTopLine\n$borderEmptyLine\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " .~~. .~~. ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " '. \ ' ' / .' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " .~ .~~~..~. _ _ ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " : .~.'~'.~. : ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ ( ) ( ) ~ | _| .'|_ -| . | . | -_| _| _| | | | . | | ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~'.~.'~' : ) |_| |__,|___| _|___|___|_| |_| |_ | | _|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ .~ ( ) ~. ~ |_| |___| |_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~' : ) ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~ .~~~. ~' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~' ")$borderBar"
|
||||||
|
|
||||||
|
me=$(whoami)
|
||||||
|
|
||||||
|
# Greetings
|
||||||
|
greetings="$borderBar$(color $greetingsColor "$(center "Welcome back, $me!")")$borderBar\n"
|
||||||
|
greetings="$greetings$borderBar$(color $greetingsColor "$(center "$(date +"%A, %d %B %Y, %T")")")$borderBar"
|
||||||
|
|
||||||
|
# System information
|
||||||
|
read loginFrom loginIP loginDate <<< $(last $me --time-format iso -2 | awk 'NR==2 { print $2,$3,$4 }')
|
||||||
|
|
||||||
|
# TTY login
|
||||||
|
if [[ $loginDate == - ]]; then
|
||||||
|
loginDate=$loginIP
|
||||||
|
loginIP=$loginFrom
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $loginDate == *T* ]]; then
|
||||||
|
login="$(date -d $loginDate +"%A, %d %B %Y, %T") ($loginIP)"
|
||||||
|
else
|
||||||
|
# Not enough logins
|
||||||
|
login="None"
|
||||||
|
fi
|
||||||
|
|
||||||
|
label1="$(extend "$login")"
|
||||||
|
label1="$borderBar $(color $statsLabelColor "Last Login....:") $label1$borderBar"
|
||||||
|
|
||||||
|
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
|
||||||
|
uptime="$uptime ($(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%d-%m-%Y %H:%M:%S"))"
|
||||||
|
|
||||||
|
label2="$(extend "$uptime")"
|
||||||
|
label2="$borderBar $(color $statsLabelColor "Uptime........:") $label2$borderBar"
|
||||||
|
|
||||||
|
label3="$(extend "$(free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }')")"
|
||||||
|
label3="$borderBar $(color $statsLabelColor "Memory........:") $label3$borderBar"
|
||||||
|
|
||||||
|
label4="$(extend "$(df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }')")"
|
||||||
|
label4="$borderBar $(color $statsLabelColor "Home space....:") $label4$borderBar"
|
||||||
|
|
||||||
|
label5="$(extend "$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9")ºC")"
|
||||||
|
label5="$borderBar $(color $statsLabelColor "Temperature...:") $label5$borderBar"
|
||||||
|
|
||||||
|
stats="$label1\n$label2\n$label3\n$label4\n$label5"
|
||||||
|
|
||||||
|
# Print motd
|
||||||
|
echo -e "$header\n$borderEmptyLine\n$greetings\n$borderEmptyLine\n$stats\n$borderEmptyLine\n$borderBottomLine" #!/bin/bash
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
function color (){
|
||||||
|
echo "\e[$1m$2\e[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
function extend (){
|
||||||
|
local str="$1"
|
||||||
|
let spaces=60-${#1}
|
||||||
|
while [ $spaces -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spaces=spaces-1
|
||||||
|
done
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function center (){
|
||||||
|
local str="$1"
|
||||||
|
let spacesLeft=(78-${#1})/2
|
||||||
|
let spacesRight=78-spacesLeft-${#1}
|
||||||
|
while [ $spacesLeft -gt 0 ]; do
|
||||||
|
str=" $str"
|
||||||
|
let spacesLeft=spacesLeft-1
|
||||||
|
done
|
||||||
|
|
||||||
|
while [ $spacesRight -gt 0 ]; do
|
||||||
|
str="$str "
|
||||||
|
let spacesRight=spacesRight-1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$str"
|
||||||
|
}
|
||||||
|
|
||||||
|
function sec2time (){
|
||||||
|
local input=$1
|
||||||
|
|
||||||
|
if [ $input -lt 60 ]; then
|
||||||
|
echo "$input seconds"
|
||||||
|
else
|
||||||
|
((days=input/86400))
|
||||||
|
((input=input%86400))
|
||||||
|
((hours=input/3600))
|
||||||
|
((input=input%3600))
|
||||||
|
((mins=input/60))
|
||||||
|
|
||||||
|
local daysPlural="s"
|
||||||
|
local hoursPlural="s"
|
||||||
|
local minsPlural="s"
|
||||||
|
|
||||||
|
if [ $days -eq 1 ]; then
|
||||||
|
daysPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $hours -eq 1 ]; then
|
||||||
|
hoursPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $mins -eq 1 ]; then
|
||||||
|
minsPlural=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$days day$daysPlural, $hours hour$hoursPlural, $mins minute$minsPlural"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
borderColor=35
|
||||||
|
headerLeafColor=32
|
||||||
|
headerRaspberryColor=31
|
||||||
|
greetingsColor=36
|
||||||
|
statsLabelColor=33
|
||||||
|
|
||||||
|
borderLine="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
borderTopLine=$(color $borderColor "┏$borderLine┓")
|
||||||
|
borderBottomLine=$(color $borderColor "┗$borderLine┛")
|
||||||
|
borderBar=$(color $borderColor "┃")
|
||||||
|
borderEmptyLine="$borderBar $borderBar"
|
||||||
|
|
||||||
|
# Header
|
||||||
|
header="$borderTopLine\n$borderEmptyLine\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " .~~. .~~. ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerLeafColor " '. \ ' ' / .' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " .~ .~~~..~. _ _ ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " : .~.'~'.~. : ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ ( ) ( ) ~ | _| .'|_ -| . | . | -_| _| _| | | | . | | ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~'.~.'~' : ) |_| |__,|___| _|___|___|_| |_| |_ | | _|_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ~ .~ ( ) ~. ~ |_| |___| |_| ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " ( : '~' : ) ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~ .~~~. ~' ")$borderBar\n"
|
||||||
|
header="$header$borderBar$(color $headerRaspberryColor " '~' ")$borderBar"
|
||||||
|
|
||||||
|
me=$(whoami)
|
||||||
|
|
||||||
|
# Greetings
|
||||||
|
greetings="$borderBar$(color $greetingsColor "$(center "Welcome back, $me!")")$borderBar\n"
|
||||||
|
greetings="$greetings$borderBar$(color $greetingsColor "$(center "$(date +"%A, %d %B %Y, %T")")")$borderBar"
|
||||||
|
|
||||||
|
# System information
|
||||||
|
read loginFrom loginIP loginDate <<< $(last $me --time-format iso -2 | awk 'NR==2 { print $2,$3,$4 }')
|
||||||
|
|
||||||
|
# TTY login
|
||||||
|
if [[ $loginDate == - ]]; then
|
||||||
|
loginDate=$loginIP
|
||||||
|
loginIP=$loginFrom
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $loginDate == *T* ]]; then
|
||||||
|
login="$(date -d $loginDate +"%A, %d %B %Y, %T") ($loginIP)"
|
||||||
|
else
|
||||||
|
# Not enough logins
|
||||||
|
login="None"
|
||||||
|
fi
|
||||||
|
|
||||||
|
label1="$(extend "$login")"
|
||||||
|
label1="$borderBar $(color $statsLabelColor "Last Login....:") $label1$borderBar"
|
||||||
|
|
||||||
|
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
|
||||||
|
uptime="$uptime ($(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%d-%m-%Y %H:%M:%S"))"
|
||||||
|
|
||||||
|
label2="$(extend "$uptime")"
|
||||||
|
label2="$borderBar $(color $statsLabelColor "Uptime........:") $label2$borderBar"
|
||||||
|
|
||||||
|
label3="$(extend "$(free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }')")"
|
||||||
|
label3="$borderBar $(color $statsLabelColor "Memory........:") $label3$borderBar"
|
||||||
|
|
||||||
|
label4="$(extend "$(df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }')")"
|
||||||
|
label4="$borderBar $(color $statsLabelColor "Home space....:") $label4$borderBar"
|
||||||
|
|
||||||
|
label5="$(extend "$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9")ºC")"
|
||||||
|
label5="$borderBar $(color $statsLabelColor "Temperature...:") $label5$borderBar"
|
||||||
|
|
||||||
|
stats="$label1\n$label2\n$label3\n$label4\n$label5"
|
||||||
|
|
||||||
|
# Print motd
|
||||||
|
echo -e "$header\n$borderEmptyLine\n$greetings\n$borderEmptyLine\n$stats\n$borderEmptyLine\n$borderBottomLine" OA
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
args=("$@")
|
||||||
|
norm="\e[0m"
|
||||||
|
blue="\e[34m"
|
||||||
|
red="\e[31m"
|
||||||
|
|
||||||
|
printf "%s \t[$blue UP $norm]\n" "$(hostname)"
|
||||||
|
for ((i=0; i < $#; i++))
|
||||||
|
{
|
||||||
|
ping -c 2 -W 1 -q ${args[$i]} 1>/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
printf "%s \t[$blue UP $norm]\n" "${args[$i]}"
|
||||||
|
else
|
||||||
|
printf "%s \t[$red DOWN $norm]\n" "${args[$i]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$1" == "ON" ];then
|
||||||
|
irsend SEND_ONCE SAMSUNG KEY_1;
|
||||||
|
elif [ "$1" == "OFF" ];then
|
||||||
|
irsend SEND_ONCE SAMSUNG KEY_POWER;
|
||||||
|
elif [ "$1" == "-a" ];then
|
||||||
|
irsend SEND_ONCE SAMSUNG $2;
|
||||||
|
elif [ "$1" == "-l" ]; then
|
||||||
|
irsend LIST SAMSUNG ""
|
||||||
|
else
|
||||||
|
printf "ON...Turn TV ON\nOFF...Turn TV OFF\n-a...Send Command\n-l...List Commands\n"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 11:30 pm
|
||||||
|
/home/lucas/Documents/Dokumente/Dokumente/Projekte/Server/scripts/wol.sh serverhost
|
||||||
|
# 00:01 am
|
||||||
|
/home/lucas/Documents/Dokumente/Dokumente/Projekte/Server/scripts/wol.sh serverhost
|
||||||
|
/home/lucas/Documents/Dokumente/Dokumente/Projekte/Server/scripts/wol.sh workhost
|
||||||
|
# 00:10
|
||||||
|
ssh serverhost /home/lucas/scripts/smartctl_long.sh
|
||||||
|
ssh serverhost /home/lucas/scripts/backup_all.sh
|
||||||
|
ssh serverhost /home/lucas/scripts/upgrade.sh
|
||||||
|
# 5:00
|
||||||
|
ssh serverhost /home/lucas/scripts/smartctl_send_results.sh
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/expect -f
|
||||||
|
log_user 0
|
||||||
|
if { [llength $argv]==0 } {
|
||||||
|
puts "Hostname missing\n(all,tv,pc,serverhost,quiethost)"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
set color [lindex $argv 1]
|
||||||
|
if { $color == "-c" } {
|
||||||
|
set red "\033\[1;31m"
|
||||||
|
set blue "\033\[1;34m"
|
||||||
|
set norm "\033\[1;0m"
|
||||||
|
} else {
|
||||||
|
set red ""
|
||||||
|
set blue ""
|
||||||
|
set norm ""
|
||||||
|
}
|
||||||
|
set ret1 ""
|
||||||
|
array set host { 0 "serverhost" 1 "quiethost" }
|
||||||
|
array set user { 0 "lucas" 1 "lucas" }
|
||||||
|
array set port { 0 "3032" 1 "1504"}
|
||||||
|
set TARGET [lindex $argv 0]
|
||||||
|
set start 0
|
||||||
|
set end -1
|
||||||
|
if { ${TARGET} == "all" || ${TARGET} == "pc" } {
|
||||||
|
set start 0
|
||||||
|
set end 1
|
||||||
|
} elseif { ${TARGET} == "serverhost" } {
|
||||||
|
set start 0
|
||||||
|
set end 0
|
||||||
|
} elseif { ${TARGET} == "quiethost" } {
|
||||||
|
set start 1
|
||||||
|
set end 1
|
||||||
|
} else {
|
||||||
|
puts "Target ${TARGET} not known"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
#if {[string match 10.0.0.26* $env(SSH_CLIENT)]} {
|
||||||
|
# exec ssh -o ConnectTimeout=4 -p 1504 lucas@quiethost notify-send "Shutdown ${TARGET}"
|
||||||
|
#}
|
||||||
|
for {set i $start} {$i <= $end} {incr i 1} {
|
||||||
|
spawn ssh -o ConnectTimeout=4 -p $port($i) $user($i)@$host($i)
|
||||||
|
expect {
|
||||||
|
"Connection timed out" {
|
||||||
|
puts "$host($i)\t\[${red} FAIL ${norm}\]"
|
||||||
|
}
|
||||||
|
"$ " {
|
||||||
|
send "cat /home/lucas/.auto_shutdown\r"
|
||||||
|
expect "$ "
|
||||||
|
set ret $expect_out(buffer)
|
||||||
|
if {[string match *no* $ret ]} {
|
||||||
|
puts "Shutdown disabled! $host($i) Shutdown aborted!"
|
||||||
|
exit 0
|
||||||
|
} else {
|
||||||
|
puts "Shutdown enabled"
|
||||||
|
}
|
||||||
|
send "ps -elf | grep scripts/backup | grep -v grep\r"
|
||||||
|
expect "$ "
|
||||||
|
set ret $expect_out(buffer)
|
||||||
|
if {[string match *bash* $ret ]} {
|
||||||
|
puts "Backup in Progress! $host($i) Shutdown aborted!"
|
||||||
|
exit 0
|
||||||
|
} else {
|
||||||
|
puts "No Backup in Progress"
|
||||||
|
}
|
||||||
|
send "ps -elf | grep scripts/upgrade | grep -v grep\r"
|
||||||
|
expect "$ "
|
||||||
|
set ret $expect_out(buffer)
|
||||||
|
if {[string match *bash* $ret ]} {
|
||||||
|
puts "Update in Progress! $host($i) Shutdown aborted!"
|
||||||
|
exit 0
|
||||||
|
} else {
|
||||||
|
puts "No Update in Progress"
|
||||||
|
}
|
||||||
|
send "sudo /sbin/shutdown -P 1 +6\r"
|
||||||
|
#send "echo Shutdown\r"
|
||||||
|
expect "$ "
|
||||||
|
set ret $expect_out(buffer)
|
||||||
|
send "exit\r"
|
||||||
|
expect "$ "
|
||||||
|
set ret1 [exec echo $ret | grep -o "Shutdown scheduled"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if {$ret1 == "Shutdown scheduled"} {
|
||||||
|
puts "$host($i)\t\[${blue} DOWN${norm} ]"
|
||||||
|
if {[string match 10.0.0.26* $env(SSH_CLIENT)]} {
|
||||||
|
exec ssh -o ConnectTimeout=4 -p 1504 lucas@quiethost notify-send "Shutdown SUCESSFULL for ${TARGET}"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
puts "$host($i)\t\[${red} FAIL${norm} ]"
|
||||||
|
if {[string match 10.0.0.26* $env(SSH_CLIENT)]} {
|
||||||
|
exec ssh -o ConnectTimeout=4 -p 1504 lucas@quiethost notify-send "Shutdown FAILED for ${TARGET}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if { ${TARGET} == "quiethost-win" } {
|
||||||
|
spawn ssh -o ConnectTimeout=6 -p 1504 LF@quiethost
|
||||||
|
expect {
|
||||||
|
"Connection timed out" {
|
||||||
|
puts "quiethost\t\[ ${red} FAIL ${norm} ]"
|
||||||
|
}
|
||||||
|
"LF>" {
|
||||||
|
send "shutdown /p\r"
|
||||||
|
expect {
|
||||||
|
"LF>Received disconnect" {
|
||||||
|
puts "quiethost\t\[${blue} DOWN${norm} ]"
|
||||||
|
send "exit\r"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if { ${TARGET} == "all" || ${TARGET} == "tv" } {
|
||||||
|
spawn bash /home/lucas/Raspberry/scripts/samsung_remote.sh OFF
|
||||||
|
puts "TV\t\[ ${blue} DOWN${norm} ]"
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mem="$(free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }')"
|
||||||
|
|
||||||
|
mem="Memory........: $mem"
|
||||||
|
|
||||||
|
space="$(df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }')"
|
||||||
|
space="Home space....: $space"
|
||||||
|
|
||||||
|
temp="$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9") ºC"
|
||||||
|
temp="Temperature...: $temp"
|
||||||
|
|
||||||
|
echo $mem
|
||||||
|
echo $space
|
||||||
|
echo $temp
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
nextcloudcmd --path Dokumente/Dokumente/Projekte/Server /home/lucas/Documents/Dokumente/Projekte/Server https://lucas:$(cat /home/lucas/.PW)@someoneslinux.ddns.net
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
scp -r -P1160 Raspberry workhost:~/Documents/Dokumente/Dokumente/Projekte/Server/Raspberry
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#wake Serverhost
|
||||||
|
printf "Wake Serverhost\n"
|
||||||
|
bash /home/lucas/Raspberry/scripts/wol.sh ec:a8:6b:8b:cc:04
|
||||||
|
for i in {1..60}; do
|
||||||
|
printf " %s " "$i"
|
||||||
|
sleep 0.3
|
||||||
|
printf "."
|
||||||
|
sleep 0.3
|
||||||
|
printf "."
|
||||||
|
sleep 0.3
|
||||||
|
done
|
||||||
|
printf "\nTrigger Timesync script\n"
|
||||||
|
ssh -p 3032 lucas@serverhost 'bash /home/lucas/scripts/time_rasp.sh'
|
||||||
|
for i in {1..5}; do
|
||||||
|
printf " %s " "$i"
|
||||||
|
sleep 0.3
|
||||||
|
printf "."
|
||||||
|
sleep 0.3
|
||||||
|
printf "."
|
||||||
|
sleep 0.3
|
||||||
|
done
|
||||||
|
printf "\nShutdown Serverhost\n"
|
||||||
|
/usr/bin/expect /home/lucas/Raspberry/scripts/shutdown.sh serverhost
|
||||||
|
printf "Date has been actualized: %s\n" "$(date)"
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "Toggling between lirc0/lirc1..."
|
||||||
|
grep lirc0 /etc/lirc/lirc_options.conf
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
echo "Switching from lirc1 to lirc0"
|
||||||
|
sudo sed -i 's/lirc1/lirc0/g' /etc/lirc/lirc_options.conf
|
||||||
|
else
|
||||||
|
echo "Switching from lirc0 to lirc1"
|
||||||
|
sudo sed -i 's/lirc0/lirc1/g' /etc/lirc/lirc_options.conf
|
||||||
|
fi
|
||||||
|
sudo service lircd restart
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
> /etc/motd
|
||||||
|
sudo apt-get update > /dev/null 2>&1
|
||||||
|
upgrades=$(sudo apt-get -s dist-upgrade | grep upgraded, | awk '{ printf "%i",$1; }')
|
||||||
|
install=$(sudo apt-get -s dist-upgrade | grep 'newly installed' | awk '{ printf "%i",$3; }')
|
||||||
|
distupgrades=$(sudo apt-get -s dist-upgrade | grep upgraded, | awk '{ printf "%i",$1; }')
|
||||||
|
distupgrades=$((10#$distupgrades - 10#$upgrades))
|
||||||
|
remove=$(sudo apt-get -s autoremove | grep upgraded, | awk '{ printf "%i",$6; }')
|
||||||
|
echo $upgrades packages can be updated. >> /etc/motd
|
||||||
|
echo $install packages will be newly installed. >> /etc/motd
|
||||||
|
echo $distupgrades dist-packages can be updated. >> /etc/motd
|
||||||
|
echo $remove packages can be removed. >> /etc/motd
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
sudo apt -y update
|
||||||
|
sudo apt -y upgrade
|
||||||
|
sudo apt -y dist-upgrade
|
||||||
|
sudo apt -y autoclean
|
||||||
|
sudo apt -y autoremove
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
ssh quiethost bash /home/lucas/scripts/wallpaperChanger.sh -X
|
||||||
Reference in new issue
Block a user