自己用ARM9实现了网络摄像头
但是家里拨号到ip老是变,导致公网外部老是访问不了。
所以想了一下,本来想用邮箱做IP记录
现在直接用php实现
<?php
if(isset($_GET["chk"]))
{
$file_pointer = fopen("ip","w");
fwrite($file_pointer,$_SERVER["REMOTE_ADDR"]);
fclose($file_pointer);
echo $_SERVER["REMOTE_ADDR"];
}else{
echo file_get_contents("ip");
}
?>
嵌入式里面每隔5分钟访问ip.php?chk=c
QT嵌入式代码
qsetip.h
#ifndef QSETIP_H
#define QSETIP_H
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QDebug>
class QSetIp : public QObject
{
Q_OBJECT
private:
QUrl url;
QNetworkAccessManager* qnam;
QNetworkReply *reply;
int httpGetId;
bool httpRequestAborted;
public:
explicit QSetIp(QObject *parent = 0);
void startRequest(QUrl url);
signals:
void httpFinish(QString result);
public slots:
void httpFinished();
};
#endif // QSETIP_H
qsetip.cpp
#include "qsetip.h"
QSetIp::QSetIp(QObject *parent) :
QObject(parent)
{
}
void QSetIp::startRequest(QUrl url)
{
qnam = new QNetworkAccessManager(this);
reply = qnam->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
}
void QSetIp::httpFinished()
{
if (httpRequestAborted) {
QString html = reply->readAll();
httpFinish(html);
qDebug()<< html;
reply = 0;
}
}
在程序启动 加入
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(runGet()));
timer->start(5000);
建立slot
void MainWindow::runGet()
{
setIpClass = new QSetIp(this);
setIpClass->startRequest(QUrl("http://www.xxxxxx.com/ip.php?chk=1"));
}