树莓派
账号:pi
密码:raspberry
1.树莓派HDMI登陆
2.树莓派串口登陆:(13条消息) 树莓派–串口登录_树莓派串口登录_一只青木呀的博客-CSDN博客
3.网络登陆树莓派:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="你的无线网名字"
psk="密码"
key_mgmt=WPA-PSK//这个是加密的方式,可以不写
}
(13条消息) 树莓派的几种登录方式及树莓派的网络配置_FHNCSDN的博客-CSDN博客
然后打开ssh功能
sudo raspi-config
最后重启一下
固定IP地址
sudo nano /etc/rc.local
在最后fi exit0之间加上
ifconfig wlan0 xxx.xxx.xx.xxx(ifconfig找到的ip)
然后重启
sudo reboot
ssh登陆,树莓派连接的WiFi要和电脑连接的WiFi是同一个(同一个局域网,这样mobaXterm才能用)
4.树莓派图形xrdp界面登陆
首先树莓派下载
sudo apt-get install xrdp
然后Windows中搜索 “远程桌面连接”输入树莓派IP就可以连接
如果连不上就关闭防火墙
或者将树莓派的xrdp进行卸载再重新安装
卸载指令
sudo apt autoremove xxxxx
树莓派和Windows的FileZilla文件共享
安装软件指令:
sudo apt-get install XXXX
树莓派换镜像源
sudo nano /etc/apt/sources.list
Linux中的库
(13条消息) Linux中的库(静态库和动态库)详解_linux 静态库_石子君的博客-CSDN博客
树莓派串口通信
首先:修改cmdline.txt文件
cd /boot
sudo vi cmdline.txt
然后删除以下内容(禁用串口调试功能,改成通信功能)
console=ttyAMA0,115200
最后重启
sudo reboot
代码如下:
#include <stdio.h>
#include <wiringSerial.h>
#include <wiringPi.h>
int main()
{
int err_ret = wiringPiSetup ();
if(err_ret == -1)
{
printf("setup failed\n");
return -1;
}
int fd = serialOpen ("/dev/ttyAMA0", 115200);
if(fd == -1)
{
printf("serial open failed\n");
return -1;
}
int cnt = 0;
for(cnt = 0 ;cnt < 10 ;cnt ++)
{
serialPutchar (fd, 'A'+cnt);
}
-- VISUAL -- 26 1,1 Top
结果如下:
树莓派交叉编译工具链的安装
树莓派mjpg-streamer实现监控功能调试
(9条消息) 树莓派安装MJPG-streamer_mjpg-streamer还维护吗_冷月枫啊的博客-CSDN博客
(9条消息) 树莓派(raspberry pi)mjpg——streamer 远程识别监控(换源+csl摄像头+usb摄像头零基础指导以及一些过程问题的解决)_放小孩的羊的博客-CSDN博客
树莓派3B + Pi摄像头+mjpg-streamer-百度经验 (baidu.com)
input_uvc.so 是usb摄像头
input_raspicam.so是树莓派摄像头
将start.sh中input_uvc.so改为input_raspicam.so
socket,tcp,udp,http,之间的区别和原理
socket、tcp、udp、http 的认识及区别 - 叫我程某某 - 博客园 (cnblogs.com)
http,https,libcurl协议相关
Http协议之libcurl实现 - 谢呈勖 - 博客园 (cnblogs.com)
url就是网址
libcurl等第三方库的通用编译方法
首先从GitHub上下载源码
https://github.com/curl/curl/releases/tag/curl-7_71_1
下载后放到Ubuntu中进行解压
tar -xjf curl-7.71.1.tar.bz2
进入解压好的文件夹
cd curl-7.71.1/
可以看看docs中的INSTALL.md,里面有各种环境的安装方法,我们当前的环境是linux
cd curl-7.71.1/
进入curl-7.71.1这个文件夹,现在开始进行编译
./configure --prefix=$PWD/_install
将编译后生成的东西放到当前工作路径的_install文件夹底下
也可以指定交叉编译工具
./configure --prefix=$PWD/_install --host=arm-linux-gnueabihf-gcc
然后
make
最后
make install
进入到_install文件夹查看一下编译生成的文件
调用libcurl编程访问百度主页
代码如下:
#include <stdio.h>
#include <curl/curl.h>
#define true 1
#define false 0
typedef unsigned int bool;
bool getUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL) // 返回结果用文件存储
return false;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: Agent-007");
curl = curl_easy_init(); // 初始化
if (curl)
{
//curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");// 代理
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);// 改协议头
curl_easy_setopt(curl, CURLOPT_URL,"http://www.baidu.com");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //将返回的http头输出到fp指向的文件
curl_easy_setopt(curl, CURLOPT_HEADERDATA, fp); //将返回的html主体数据输出到fp指向的文件
res = curl_easy_perform(curl); // 执行
if (res != 0) {
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
}
bool postUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL)
return false;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&logintype=uid&u=xieyan&psw=xxx86"); // 指定post内容
//curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");
curl_easy_setopt(curl, CURLOPT_URL, " http://mail.sina.com.cn/cgi-bin/login.cgi "); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
int main(void)
{
getUrl("/tmp/get.html");
postUrl("/tmp/post.html");
}
编译
gcc test2.c -I ../curl-7.71.1/include/ -L ../curl-7.71.1/_install/lib/ -lcurl
有报错
需要配置环境变量
export LD_LIBRARY_PATH=/home/zlw/DailyCode/raspberry_study/curl-7.71.1/_install/lib
也可以永久配置环境:
gedit ~/.bashrc
在最后添加以下内容
export LD_LIBRARY_PATH=/home/zlw/DailyCode/raspberry_study/curl-7.71.1/_install/lib
然后重启虚拟机就OK了
这样子就可以运行了
libcurl函数库常用字段解读并设置数据读取回调函数
read_func是回调函数
代码:
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#define true 1
#define false 0
typedef unsigned int bool;
size_t read_func( void *ptr, size_t size, size_t nmemb, void *stream)
{
char buf[10240] = {0};
strncpy(buf, ptr, 10240);
printf("======================get data======================\n");
printf("%s\n",buf);
}
bool getUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL) // 返回结果用文件存储
return false;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: Agent-007");
curl = curl_easy_init(); // 初始化
if (curl)
{
//curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");// 代理
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);// 改协议头
curl_easy_setopt(curl, CURLOPT_URL,"http://www.baidu.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, read_func); //通过回调函数存储数据
//curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //将返回的http头输出到fp指向的文件
//curl_easy_setopt(curl, CURLOPT_HEADERDATA, fp); //将返回的html主体数据输出到fp指向的文件
res = curl_easy_perform(curl); // 执行
if (res != 0) {
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
}
bool postUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL)
return false;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&logintype=uid&u=xieyan&psw=xxx86"); // 指定post内容
//curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");
curl_easy_setopt(curl, CURLOPT_URL, " http://mail.sina.com.cn/cgi-bin/login.cgi "); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
int main(void)
{
getUrl("/tmp/get.html");
postUrl("/tmp/post.html");
}
输出结果:
(9条消息) Ubuntu连接不上网络问题的解决方法_ubuntu连接不了网络的解决方法_菜鸡什么时候能变强的博客-CSDN博客
编程实现人脸识别第一次
平台:翔云_人工智能_API_服务平台 (netocr.com)
代码:
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#define true 1
#define false 0
typedef unsigned int bool;
size_t read_func( void *ptr, size_t size, size_t nmemb, void *stream)
{
char buf[1024] = {0};
strncpy(buf, ptr, 1024);
printf("======================get data======================\n");
printf("%s\n",buf);
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char img1[12];
char img2[12];
char *key = "MPWeajiYjAtrYDfZweE8vk";
char *secret = " 9e300b424e7e4a20a7dabd3799410c56";
int typeID = 21;
char *formate = "xml";
postString = (char*)malloc(strlen(key)+strlen(secret)+2048);
//字符串拼接
sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeID=%d&formate=%s",
"", "", key, secret, typeID, formate);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容
curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, read_func); //通过回调函数存储数据
res = curl_easy_perform(curl);
printf("OK:%d\n",res);
curl_easy_cleanup(curl);
}
return true;
}
int main(void)c
{
postUrl();
}
运行结果:
原因:没有传递两张图片参数
编译openssl支持libcurl的https访问
首先删除之前编译后生成的文件(因为翔云这个平台需要ssl)
rm -rf _install
然后重新配置
./configure --prefix=$PWD/_install --with-ssl
安装openssl
(9条消息) 交叉编译:OpenSSL_使wget支持https_钱德勒宾的博客-CSDN博客
看README,了解怎么安装
再去看INSTALL,看看怎么安装
安装到系统路径底下去
./config
然后
make
最后
sudo make install
然后进入到cd curl-7.71.1/目录,重新进行编译curl
./configure --prefix=$PWD/_install --with-ssl
make
sudo make install
然后就可以运行代码来访问翔云平台(将代码的typeID改为typeId这样就解决了产品类型错误)
编程实现人脸识别第二次加入图片base64编码
代码如下:
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#define true 1
#define false 0
typedef unsigned int bool;
size_t read_func( void *ptr, size_t size, size_t nmemb, void *stream)
{
char buf[1024] = {0};
strncpy(buf, ptr, 1024);
printf("======================get data======================\n");
printf("%s\n",buf);
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char *img1;
char *img2;
char *key = "MPWeajiYjAtrYDfZweE8vk";
char *secret = "9e300b424e7e4a20a7dabd3799410c56";
int typeID = 21;
char *formate = "xml";
system("base64 pyy1.jpg > tmpFile1");
system("base64 pyy2.jpg > tmpFile2");
int fd1 = open("./tmpFile1",O_RDWR);
int fd2 = open("./tmpFile2",O_RDWR);
int fd1_len = lseek(fd1,0,SEEK_END);
lseek(fd1,0,SEEK_SET);
int fd2_len = lseek(fd2,0,SEEK_END);
lseek(fd2,0,SEEK_SET);
img1 = (char*)malloc(fd1_len+20);
img2 = (char*)malloc(fd2_len+20);
memset(img1,'\0',fd1_len+20);
memset(img2,'\0',fd2_len+20);
read(fd1,img1,fd1_len);
read(fd2,img2,fd2_len);
postString = (char*)malloc(strlen(key)+strlen(secret)+fd1_len+fd2_len+1024);
memset(postString,'\0',strlen(postString));
//字符串拼接
sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&formate=%s",
img1, img2, key, secret, typeID, formate);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容
curl_easy_setopt(curl, CURLOPT_URL,"https://netocr.com/api/faceliu.do"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, read_func); //通过回调函数存储数据
res = curl_easy_perform(curl);
printf("OK:%d\n",res);
curl_easy_cleanup(curl);
}
free(img1);
free(img2);
free(postString);
close(fd1);
close(fd2);
return true;
}
int main(void)
{
postUrl();
}
结果:
代码中的这些内容要与网页的相对应
人脸识别成功并封装Base64编码函数
代码如下:
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#define true 1
#define false 0
typedef unsigned int bool;
size_t read_func( void *ptr, size_t size, size_t nmemb, void *stream)
{
char buf[1024] = {0};
strncpy(buf, ptr, 1024);
printf("======================get data======================\n");
printf("%s\n",buf);
printf("=====================result=======================\n");
if(strstr(buf,"是") != NULL)
{
printf("the same person\n");
}
else
{
printf("different person\n");
}
}
char* getPicBase64FromFile(char *filePath)
{
char *bufPic;
char cmd[128]={'\0'};
sprintf(cmd,"base64 %s >tmpFile",filePath);
system(cmd);
int fd = open("./tmpFile",O_RDWR);
int fd_len = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
bufPic = (char*)malloc(fd_len+2);
memset(bufPic,'\0',fd_len+2);
read(fd,bufPic,fd_len);
close(fd);
system("rm -rf tmpFile");
return bufPic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char *img1;
char *img2;
char *key = "MPWeajiYjAtrYDfZweE8vk";
char *secret = "9e300b424e7e4a20a7dabd3799410c56";
int typeID = 21;
char *formate = "xml";
//图片转字符流
img1 = getPicBase64FromFile("./pyy1.jpg");
img2 = getPicBase64FromFile("./pyy2.jpg");
postString = (char*)malloc(strlen(key)+strlen(secret)+strlen(img1)+strlen(img2)+1024);
memset(postString,'\0',strlen(postString));
//字符串拼接
sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&formate=%s",
img1, img2, key, secret, typeID, formate);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容
curl_easy_setopt(curl, CURLOPT_URL,"https://netocr.com/api/faceliu.do"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, read_func); //通过回调函数存储数据
res = curl_easy_perform(curl);
printf("OK:%d\n",res);
curl_easy_cleanup(curl);
}
free(img1);
free(img2);
free(postString);
return true;
}
int main(void)
{
postUrl();
}