Commit 78c45f77 authored by 957dd's avatar 957dd

x

parent bea11fc2
#ifndef __GPIO_H__
#define __GPIO_H__
#endif
\ No newline at end of file
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#define __MAIN_H__ #define __MAIN_H__
#define filename "/home/orangepi/car/master/Deviceld.txt" #define filename "/home/orangepi/car/master/Deviceld.txt"
pthread_t thread[5]; pthread_t thread[5];
......
#ifndef __MQTT_H__ #ifndef __MQTT_H__
#define __MQTT_H__ #define __MQTT_H__
#define CLIENT_ID "carorship123" extern char* TOPIC ;//="app2dev/controlcar0004"
extern char* TOPIC2 ;//="dev2app/controlcar0004"
extern char* TOPIC3;//= "controlcar0004"
#define BROKER_ADDRESS "119.45.167.177" #define BROKER_ADDRESS "119.45.167.177"
#define BROKER_PORT 1883 #define BROKER_PORT 1883
extern char* TOPIC ;//="app2dev/controlcar0004"
extern char* TOPIC2 ;//="dev2app/controlcar0004"
extern char* TOPIC3;//= "controlcar0004"
#define USERNAME "admin" // 替换为你的用户名 #define USERNAME "admin" // 替换为你的用户名
#define PASSWORD "admin" // 替换为你的密码 #define PASSWORD "admin" // 替换为你的密码
......
File added
File added
#include "wiringPi.h"
\ No newline at end of file
File added
File added
File added
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
#include "gps.h" #include "gps.h"
#include "opensh.h" #include "opensh.h"
char* TOPIC;
char* TOPIC2;
char* TOPIC3;
int gPwmCount = 0; // 计数 int gPwmCount = 0; // 计数
int gmessage_type=10086; int gmessage_type=10086;
...@@ -28,9 +31,7 @@ unsigned char gvalt[4]; ...@@ -28,9 +31,7 @@ unsigned char gvalt[4];
struct mosquitto *mosq; struct mosquitto *mosq;
time_t gStart; time_t gStart;
char* TOPIC=NULL;
char* TOPIC2=NULL;
char* TOPIC3=NULL;
int mqtt_init() int mqtt_init()
{ {
......
File added
...@@ -20,12 +20,16 @@ char gwebcam[254];//存放启动火狐网站命令 ...@@ -20,12 +20,16 @@ char gwebcam[254];//存放启动火狐网站命令
int opencamsh() int opencamsh()
{ {
const char* url = "https://jywy.yd-ss.com?dev=";
char urls[50];
setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo sprintf(urls,"%s%s",url,TOPIC3);
sprintf(gwebcam,"su - orangepi firefox --new-window https://jywy.yd-ss.com?dev=%s &",TOPIC3);
//setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo
sprintf(gwebcam,"su - orangepi chromium-browser %s",urls);
system(gwebcam); system(gwebcam);
printf("%s\n",gwebcam); printf("%s\n",gwebcam);
printf("close cam\n"); printf("open cam\n");
return 0; return 0;
...@@ -34,7 +38,8 @@ int opencamsh() ...@@ -34,7 +38,8 @@ int opencamsh()
void refresh_cam()//使用xdottol进行模拟刷新页面 void refresh_cam()//使用xdottol进行模拟刷新页面
{ {
//system(SHELLFILECLOSE); //system(SHELLFILECLOSE);
const char *search_command = "xdotool search --name \"Mozilla Firefox\""; setenv("XAUTHORITY", "/home/orangepi/.Xauthority", 1);
const char *search_command = "xdotool search --name \"Mozilla chromium-browser\"";
FILE *fp = popen(search_command, "r"); FILE *fp = popen(search_command, "r");
if (!fp) { if (!fp) {
perror("Failed to execute search command"); perror("Failed to execute search command");
......
File added
File added
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
char buffer[30]; // 用于存储文件内容 char buffer[30]; // 用于存储文件内容
pthread_mutex_t topic3_mutex;
void *serial_usart1(void *arg) void *serial_usart1(void *arg)
{ {
printf("serial_usart 1 start\n"); printf("serial_usart 1 start\n");
...@@ -67,11 +70,14 @@ void *Mqttbeat(void *arg) ...@@ -67,11 +70,14 @@ void *Mqttbeat(void *arg)
Delay_Ms(20,0); Delay_Ms(20,0);
refresh_cam(); refresh_cam();
Delay_Ms(10,0); Delay_Ms(10,0);
while(1) while(1)
{ {
ipaddr();//获取ip ipaddr();//获取ip
Delay_Ms(3,0); Delay_Ms(3,0);
pthread_mutex_lock(&topic3_mutex);
mqtt_wirte();//心跳,3s一个 mqtt_wirte();//心跳,3s一个
pthread_mutex_unlock(&topic3_mutex);
} }
...@@ -82,8 +88,11 @@ void *Mqttbeat(void *arg) ...@@ -82,8 +88,11 @@ void *Mqttbeat(void *arg)
void *opensh(void *arg) void *opensh(void *arg)
{ {
Delay_Ms(10,0); Delay_Ms(10,0);
pthread_mutex_lock(&topic3_mutex);
printf("open cam\n"); printf("open cam\n");
pthread_mutex_unlock(&topic3_mutex);
opencamsh();//10s后打开火狐游览器并且进入网址 opencamsh();//10s后打开火狐游览器并且进入网址
return NULL; return NULL;
} }
...@@ -99,8 +108,10 @@ void *serial_usart2(void *arg) ...@@ -99,8 +108,10 @@ void *serial_usart2(void *arg)
void *Mqtt_onnect(void *arg) void *Mqtt_onnect(void *arg)
{ {
Delay_Ms(5,0); Delay_Ms(5,0);
pthread_mutex_lock(&topic3_mutex);
mqtt_init();//mqtt初始化 mqtt_init();//mqtt初始化
mqtt_create(mosq);//创建mqtt客户端 mqtt_create(mosq);//创建mqtt客户端
pthread_mutex_unlock(&topic3_mutex);
while(1) while(1)
{ {
mqtt_create(mosq); mqtt_create(mosq);
...@@ -144,18 +155,30 @@ char *device_inspect() ...@@ -144,18 +155,30 @@ char *device_inspect()
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Delay_Ms(60,0);
TOPIC=malloc(21); if (pthread_mutex_init(&topic3_mutex, NULL) != 0) {
TOPIC2=malloc(21); fprintf(stderr, "Mutex initialization failed\n");
TOPIC3= malloc(15); return EXIT_FAILURE;
TOPIC3=device_inspect(); }
Delay_Ms(10,0);
const char *readbuf=device_inspect();
TOPIC=malloc(24);
TOPIC2=malloc(24);
TOPIC3= malloc(16);
//TOPIC3=device_inspect();//读取文件内容
//sprintf(TOPIC3,"%s",buffer); //sprintf(TOPIC3,"%s",buffer);
//strcpy(TOPIC3,device_inspect()); //strcpy(TOPIC3,device_inspect());
sprintf(TOPIC2,"dev2app/%s",TOPIC3); pthread_mutex_lock(&topic3_mutex);
sprintf(TOPIC,"app2dev/%s",TOPIC3); sprintf(TOPIC2,"dev2app/%s",readbuf);
sprintf(TOPIC,"app2dev/%s",readbuf);
sprintf(TOPIC3,"%s",readbuf);
printf("1:%s,2:%s,3:%s\n",TOPIC,TOPIC2,TOPIC3); printf("1:%s,2:%s,3:%s\n",TOPIC,TOPIC2,TOPIC3);
system("pkill firefox"); pthread_mutex_unlock(&topic3_mutex);
system("pkill chromium-browser");
gStart=time(NULL);//开始时间戳 gStart=time(NULL);//开始时间戳
...@@ -164,7 +187,7 @@ int main(int argc, char *argv[]) { ...@@ -164,7 +187,7 @@ int main(int argc, char *argv[]) {
ipaddr();//获取ip ipaddr();//获取ip
thread_start(serial_usart1,AppExit,Mqttbeat,serial_usart2,opensh,Mqtt_onnect); thread_start(serial_usart1,AppExit,Mqttbeat,serial_usart2,opensh,Mqtt_onnect);//开启线程
thread_end(); thread_end();
......
File added
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