Commit bea11fc2 authored by 957dd's avatar 957dd

orangepi

parent 9dd2aa26
...@@ -28,6 +28,6 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc); ...@@ -28,6 +28,6 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc);
void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) ; void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) ;
void mqtt_MAC_wirte(); void mqtt_MAC_wirte();
void mqtt_wirte(); void mqtt_wirte();
int mqtt_cycle(struct mosquitto *mosq); void mqtt_cycle(struct mosquitto *mosq);
int mqtt_clean(struct mosquitto *mosq); void mqtt_clean(struct mosquitto *mosq);
#endif #endif
\ No newline at end of file
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
//#define SHELLFILE "/home/kickpi/car/master/camopen.sh" //#define SHELLFILE "/home/kickpi/car/master/camopen.sh"
//#define SHELLFILECLOSE "/home/kickpi/car/master/recam.sh" //#define SHELLFILECLOSE "/home/kickpi/car/master/recam.sh"
extern char gwebcam[100]; extern char gwebcam[254];
int opencamsh(); int opencamsh();
void refresh_cam(); void refresh_cam();
int reconnect_4g();
#endif #endif
\ No newline at end of file
File deleted
File deleted
...@@ -29,6 +29,8 @@ int ipaddr() { ...@@ -29,6 +29,8 @@ int ipaddr() {
printf("ip:%s\n",ip_address); printf("ip:%s\n",ip_address);
freeifaddrs(ifap); freeifaddrs(ifap);
return 0;
} }
File deleted
...@@ -28,9 +28,9 @@ unsigned char gvalt[4]; ...@@ -28,9 +28,9 @@ unsigned char gvalt[4];
struct mosquitto *mosq; struct mosquitto *mosq;
time_t gStart; time_t gStart;
char* TOPIC; char* TOPIC=NULL;
char* TOPIC2; char* TOPIC2=NULL;
char* TOPIC3; char* TOPIC3=NULL;
int mqtt_init() int mqtt_init()
{ {
...@@ -43,6 +43,7 @@ int mqtt_init() ...@@ -43,6 +43,7 @@ int mqtt_init()
} }
mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
return 0;
} }
void on_connect(struct mosquitto *mosq, void *obj, int rc) //回调函数 void on_connect(struct mosquitto *mosq, void *obj, int rc) //回调函数
...@@ -52,7 +53,6 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc) //回调函数 ...@@ -52,7 +53,6 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc) //回调函数
{ {
printf("Connected to broker\n"); printf("Connected to broker\n");
mosquitto_subscribe(mosq, NULL, TOPIC, 0); mosquitto_subscribe(mosq, NULL, TOPIC, 0);
time_t start=time(NULL);
} }
else else
{ {
...@@ -60,7 +60,7 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc) //回调函数 ...@@ -60,7 +60,7 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc) //回调函数
} }
} }
void mqtt_wirte() void mqtt_wirte()//心跳格式
{ {
int message=1; int message=1;
...@@ -72,12 +72,7 @@ void mqtt_wirte() ...@@ -72,12 +72,7 @@ void mqtt_wirte()
cJSON_AddStringToObject(body, "ID", TOPIC); cJSON_AddStringToObject(body, "ID", TOPIC);
cJSON_AddStringToObject(body, "N", glat); cJSON_AddStringToObject(body, "N", glat);
cJSON_AddStringToObject(body, "E", glon); cJSON_AddStringToObject(body, "E", glon);
if(gmessage_type==0)
{
message=0;
}else{
message=1;
}
cJSON_AddNumberToObject(head, "message_type",message); cJSON_AddNumberToObject(head, "message_type",message);
cJSON_AddItemToObject(root, "body", body); cJSON_AddItemToObject(root, "body", body);
cJSON_AddItemToObject(root, "head",head); cJSON_AddItemToObject(root, "head",head);
...@@ -90,60 +85,6 @@ void mqtt_wirte() ...@@ -90,60 +85,6 @@ void mqtt_wirte()
} }
void message_0()//message_type为0时候要改变的值
{
for(int i=1;i<=4;i++)
{
gPwmCount = 0;
switch(i)
{
case 1:
gvalt[0]= gtypeTemp;
gvalt[1]=1;
gvalt[2]=0;
printf("gtypeTemp:%d\n",gvalt[0]);
printf("gmodeTemp:%d\n",gvalt[1]);
printf("gvalTemp:%d\n",gvalt[2]);
serial_Write(gvalt);
break;
case 2:
gvalt[0]= gtypeTemp;
gvalt[1]=2;
gvalt[2]=0;
printf("gtypeTemp:%d\n",gvalt[0]);
printf("gmodeTemp:%d\n",gvalt[1]);
printf("gvalTemp:%d\n",gvalt[2]);
serial_Write(gvalt);
break;
case 3:
gvalt[0]= gtypeTemp;
gvalt[1]=3;
gvalt[2]=0;
printf("gtypeTemp:%d\n",gvalt[0]);
printf("gmodeTemp:%d\n",gvalt[1]);
printf("gvalTemp:%d\n",gvalt[2]);
serial_Write(gvalt);
break;
case 4:
gvalt[0]= gtypeTemp;
gvalt[1]=4;
gvalt[2]=0;
printf("gtypeTemp:%d\n",gvalt[0]);
printf("gmodeTemp:%d\n",gvalt[1]);
printf("gvalTemp:%d\n",gvalt[2]);
serial_Write(gvalt);
break;
default:
break;
}
}
printf("已断开连接\n");
}
void message_3(cJSON *body,cJSON *pwm_ctrl)//message_type为3,控制pwm void message_3(cJSON *body,cJSON *pwm_ctrl)//message_type为3,控制pwm
{ {
...@@ -173,7 +114,7 @@ void message_3(cJSON *body,cJSON *pwm_ctrl)//message_type为3,控制pwm ...@@ -173,7 +114,7 @@ void message_3(cJSON *body,cJSON *pwm_ctrl)//message_type为3,控制pwm
serial_Write(gvalt); serial_Write(gvalt);
} }
void message_4(cJSON *body, cJSON *pin_setctrl) void message_4(cJSON *body, cJSON *pin_setctrl)//message 为4时候
{ {
if (!cJSON_IsObject(pin_setctrl)) if (!cJSON_IsObject(pin_setctrl))
{ {
...@@ -192,7 +133,8 @@ void message_4(cJSON *body, cJSON *pin_setctrl) ...@@ -192,7 +133,8 @@ void message_4(cJSON *body, cJSON *pin_setctrl)
serial_Write(gvalt); serial_Write(gvalt);
} }
void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) { void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) //消息回环函数
{
time_t end = time(NULL); time_t end = time(NULL);
...@@ -238,6 +180,7 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag ...@@ -238,6 +180,7 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
free(payload_str); free(payload_str);
return; return;
} }
//提取 body数据段
cJSON *body = cJSON_GetObjectItem(json, "body"); cJSON *body = cJSON_GetObjectItem(json, "body");
if (!cJSON_IsObject(body)) if (!cJSON_IsObject(body))
{ {
...@@ -258,9 +201,6 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag ...@@ -258,9 +201,6 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
switch(gmessage_type) switch(gmessage_type)
{ {
case 0:
message_0();
break;
case 2: case 2:
refresh_cam(); refresh_cam();
break; break;
...@@ -306,14 +246,15 @@ void mqtt_create(struct mosquitto *mosq) //创建mqtt客服端 ...@@ -306,14 +246,15 @@ void mqtt_create(struct mosquitto *mosq) //创建mqtt客服端
} }
int mqtt_cycle(struct mosquitto *mosq) void mqtt_cycle(struct mosquitto *mosq)
{ {
mosquitto_loop_forever(mosq, -1, 1); // -1 表示无限等待,1 表示处理消息的最大数量 mosquitto_loop_forever(mosq, -1, 1); // -1 表示无限等待,1 表示处理消息的最大数量
} }
int mqtt_clean(struct mosquitto *mosq) void mqtt_clean(struct mosquitto *mosq)
{ {
// 清理 // 清理
mosquitto_destroy(mosq); mosquitto_destroy(mosq);
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
} }
\ No newline at end of file
File deleted
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
#include "opensh.h" #include "opensh.h"
char gwebcam[100]; char gwebcam[254];//存放启动火狐网站命令
int opencamsh() int opencamsh()
{ {
setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo
sprintf(gwebcam,"sudo firefox --new-window https://jywy.yd-ss.com?dev=%s &",TOPIC3); sprintf(gwebcam,"su - orangepi firefox --new-window https://jywy.yd-ss.com?dev=%s &",TOPIC3);
system(gwebcam); system(gwebcam);
printf("%s\n",gwebcam); printf("%s\n",gwebcam);
printf("close cam\n"); printf("close cam\n");
...@@ -31,7 +31,7 @@ int opencamsh() ...@@ -31,7 +31,7 @@ int opencamsh()
} }
void refresh_cam() void refresh_cam()//使用xdottol进行模拟刷新页面
{ {
//system(SHELLFILECLOSE); //system(SHELLFILECLOSE);
const char *search_command = "xdotool search --name \"Mozilla Firefox\""; const char *search_command = "xdotool search --name \"Mozilla Firefox\"";
...@@ -63,24 +63,3 @@ void refresh_cam() ...@@ -63,24 +63,3 @@ void refresh_cam()
printf("recam\n"); printf("recam\n");
} }
int reconnect_4g()
{
FILE *file = fopen("/etc/resolv.conf", "w");
if (file == NULL) {
perror("Failed to open /etc/resolv.conf");
return 1;
}
// 写入 nameserver 8.8.8.8
const char *nameserver = "nameserver 8.8.8.8\n";
if (fputs(nameserver, file) == EOF) {
perror("Failed to write to /etc/resolv.conf");
fclose(file);
return 1;
}
// 关闭文件
fclose(file);
return 0;
}
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "delay.h" #include "delay.h"
#include "opensh.h" #include "opensh.h"
char buffer[15]; // 用于存储文件内容 char buffer[30]; // 用于存储文件内容
void *serial_usart1(void *arg) void *serial_usart1(void *arg)
{ {
...@@ -157,8 +157,6 @@ int main(int argc, char *argv[]) { ...@@ -157,8 +157,6 @@ int main(int argc, char *argv[]) {
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"); system("pkill firefox");
//reconnect_4g();
gStart=time(NULL);//开始时间戳 gStart=time(NULL);//开始时间戳
serial_Init();//串口初始化 serial_Init();//串口初始化
......
File deleted
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