Commit 91eeaa51 authored by 957dd's avatar 957dd

delete shell and add mac has topic and camsite back,add duoji

parent 3ccea9e8
This source diff could not be displayed because it is too large. You can view the blob instead.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>
#include "mqtt.h"
char TOPIC[18];
void get_mac_address(const char *iface) {
int sock;
struct ifreq ifr;
sock = socket(AF_INET, SOCK_DGRAM, 0); // 创建套接字
if (sock < 0) {
perror("Socket creation failed");
return;
}
strncpy(ifr.ifr_name, iface, IFNAMSIZ - 1); // 指定网络接口
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { // 获取硬件地址
perror("ioctl failed");
close(sock);
//return;
}
unsigned char *mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
printf("MAC address of %s: %02X:%02X:%02X:%02X:%02X:%02X\n",
iface, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
sprintf(TOPIC,"%02X:%02X:%02X:%02X:%02X:%02X",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
close(sock); // 关闭套接字
}
\ No newline at end of file
#ifndef __MAC_H__
#define __MAC_H__
extern char TOPIC[18];
void get_mac_address(const char *iface) ;
#endif
No preview for this file type
......@@ -4,7 +4,7 @@
#include "serial.h"
#include "delay.h"
#include "opensh.h"
#include "mac.h"
void *serial_usart1(void *arg)
......@@ -85,7 +85,8 @@ int main(int argc, char *argv[]) {
gStart=time(NULL);//开始时间戳
get_mac_address("eth0");
serial_Init();//串口初始化
mqtt_init();//mqtt初始化
......@@ -94,8 +95,13 @@ int main(int argc, char *argv[]) {
ipaddr();//获取ip
mqtt_wirte();//mqtt心跳首次发送
//mosquitto_publish(mosq, NULL, "macmqtt", strlen(TOPIC), TOPIC, 0, false);
mqtt_MAC_wirte();
Delay_Ms(1,0);
mqtt_MAC_wirte();
Delay_Ms(1,0);
mqtt_MAC_wirte();
thread_start(serial_usart1,AppExit,Mqttbeat,serial_usart2,opensh);
mqtt_cycle(mosq);
......
......@@ -47,7 +47,15 @@ int mqtt_init()
//int init_mqtt(struct mosquitto *mosq)
void mqtt_MAC_wirte()
{
cJSON *root = cJSON_CreateObject();
cJSON *body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "TOPIC", TOPIC);
cJSON_AddItemToObject(root, "body", body);
char *payload = cJSON_PrintUnformatted(root);
mosquitto_publish(mosq, NULL, "macmqtt", strlen(payload), payload, 0, false);
}
void mqtt_wirte()
{
......@@ -80,7 +88,6 @@ void mqtt_wirte()
void message_0()//message_type为0时候要改变的值
{
for(int i=1;i<=4;i++)
......@@ -269,6 +276,7 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
}
}
int mqtt_create(struct mosquitto *mosq) //创建mqtt客服端
{
......
......@@ -7,13 +7,14 @@
#include <pthread.h>
#include "ip.h"
#include "serial.h"
#include "mac.h"
#define CLIENT_ID "carorship123"
#define BROKER_ADDRESS "119.45.167.177"
#define BROKER_PORT 1883
#define TOPIC "controcar0004"
//#define TOPIC "controcar0004"
#define USERNAME "admin" // 替换为你的用户名
#define PASSWORD "admin" // 替换为你的密码
......@@ -31,6 +32,7 @@ int mqtt_init();
int mqtt_create(struct mosquitto *mosq);
void on_connect(struct mosquitto *mosq, void *obj, int rc);
void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) ;
void mqtt_MAC_wirte();
void mqtt_wirte();
int mqtt_cycle(struct mosquitto *mosq);
int mqtt_clean(struct mosquitto *mosq);
......
#include <stdio.h>
#include <stdlib.h>
#include "opensh.h"
#include "mac.h"
#include <string.h>
char webcam[100];
int opencamsh()
{
setenv("DISPLAY", ":0", 1);//设置环境变量
system("sudo firefox --new-window https://jywy.yd-ss.com?dev=controcar0004 &");
setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004
sprintf(webcam,"sudo firefox --new-window https://jywy.yd-ss.com?dev=%s &",TOPIC);
system(webcam);
printf("%s\n",webcam);
printf("close cam\n");
}
......@@ -14,6 +20,31 @@ int opencamsh()
void refresh_cam()
{
system(SHELLFILECLOSE);
const char *search_command = "xdotool search --name \"Mozilla Firefox\"";
FILE *fp = popen(search_command, "r");
if (!fp) {
perror("Failed to execute search command");
return;
}
char window_id[32];
while (fgets(window_id, sizeof(window_id), fp) != NULL) {
// 去掉换行符
window_id[strcspn(window_id, "\n")] = '\0';
// 使用 xdotool 激活窗口并发送 Ctrl+r 快捷键进行刷新
char activate_command[128];
snprintf(activate_command, sizeof(activate_command), "xdotool windowactivate --sync %s key Ctrl+r", window_id);
printf("Executing: %s\n", activate_command);
if (system(activate_command) != 0) {
fprintf(stderr, "Failed to refresh window with ID: %s\n", window_id);
} else {
printf("Refreshed window with ID: %s\n", window_id);
}
}
// 关闭文件指针
pclose(fp);
printf("recam\n");
}
#!/bin/bash
irefox_windows=$(xdotool search --name "Call 1V1 — Mozilla Firefox")
# 判断是否找到 Firefox 窗口
#if [ -z "$firefox_windows" ]; then
#echo "没有找到任何 Firefox 窗口。"
#exit 1
#fi
# 刷新所有找到的 Firefox 窗口 #echo "刷新窗口 ID: $window"
for window in $irefox_windows; do
xdotool windowactivate $window key Ctrl+r
done
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment