[英]Data from Arduino over Ethernet and wget, instead of python
The topic of an Arduino serving data via Ethernet seems to have been discussed in a few places: 似乎已经在几个地方讨论了通过以太网为数据提供服务的Arduino主题:
1) Arduino ethernet communication 1) Arduino以太网通讯
and 和
2) Dumping data over ethernet with an arduino client / python server 2) 使用arduino客户端/ python服务器通过以太网转储数据
The way I like the most is the Arduino WebClient option which was mentioned in the first post: 我最喜欢的方式是在第一篇文章中提到的Arduino WebClient选项:
https://www.arduino.cc/en/Tutorial/WebClient https://www.arduino.cc/en/Tutorial/WebClient
The second post involves some Python (2.7), but it didn't seem like the problem was solved. 第二篇文章涉及一些Python(2.7),但似乎问题并未解决。 I was also wondering if it was easier to do with wget.
我还想知道使用wget是否更容易。
If you have an Arduino acting as a simple server giving information: 如果您将Arduino用作提供信息的简单服务器:
/*
Simply put out data as a server
*/
#include <SPI.h>
#include <Ethernet.h>
unsigned long current_time;
unsigned long old_time;
// Ethernet stuff
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0x12, 0x34
};
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
boolean notYetConnected;
// IP Address is set here
IPAddress ip(192, 168, 3, 50);
void setup()
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
{
int i;
Serial.begin(9600);
// Ethernet option
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("# For Ethernet connection, server is at ");
Serial.println(Ethernet.localIP());
Serial.print("# \n");
}
void loop()
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
{
int i;
current_time = millis();
// dump data every 100 ms
if ((current_time - old_time) > 100)
{
// data from sensor spoofed here
int datavalue = random(0, 100);
Serial.print(current_time);
Serial.print(",");
Serial.print(datavalue);
Serial.print("\n");
server.print(current_time);
server.print(",");
server.print(datavalue);
server.print("\n");
// get delta time
old_time = current_time;
}
}
... you can use 'wget 192.168.3.50' to get the data, which dumps to a file (default index.html). ...您可以使用“ wget 192.168.3.50”获取数据,该数据转储到文件中(默认为index.html)。
This isn't the typical client/server thing, where a program asks for information, and then it is returned; 这不是典型的客户机/服务器程序,程序在其中询问信息,然后将其返回。 the server just dumps data out, and you can point a web browser to the IP address, or, as seen above, use wget.
服务器只是将数据转储出去,您可以将Web浏览器指向IP地址,或者如上所示,使用wget。
When you 'set and forget' the wget command, data is recorded pretty well. 当您“设置并忘记” wget命令时,数据记录得很好。 I just did a test for 1.75+ hours and got 60K+ lines (once every 100 ms), and the system works.
我刚刚进行了1.75+小时的测试,并获得了60K +条线路(每100毫秒一次),系统正常工作。
I've noticed that if I stop the 'wget' command, and restart it, after a few times, the wget process hangs up, and I have to reset my Arduino. 我注意到,如果我停止“ wget”命令,然后重新启动它,几次后,wget进程将挂起,并且我必须重置Arduino。
A full client-server program seems a better way as per: 完整的客户端-服务器程序似乎是一种更好的方法:
https://giovanniorgantini.wordpress.com/2015/03/14/getting-data-over-the-internet-with-arduino/ https://giovanniorgantini.wordpress.com/2015/03/14/getting-data-over-the-internet-with-arduino/
... and I'll be working on this now (the original client is in C, if someone can point me to a simple python-Arduino program, otherwise, I'll be looking at a simple python client), but was wondering: ...并且我现在将继续研究(原始客户端在C中,如果有人可以将我指向一个简单的python-Arduino程序,否则,我将在看一个简单的python客户端),但我想知道:
1) Why would stopping the 'wget' (control-C) cause problems in restarting the wget process, where the system hangs up with: 1)为什么停止'wget'(control-C)会在重新启动wget进程时导致问题,系统在此挂起:
user@machine:$ wget 192.168.3.50 --2018-02-12 19:58:54-- http://192.168.3.50/ Connecting to 192.168.3.50:80...
user @ machine:$ wget 192.168.3.50 --2018-02-12 19:58:54-- http://192.168.3.50/正在连接到192.168.3.50:80 ...
One reason to stop the data stream is when you are stopping a test, or, programmatically, to start another data file. 停止数据流的一个原因是停止测试或以编程方式启动另一个数据文件的时间。
2) Is it possible to parse wget output, so that data can be saved in files every N data points or N seconds? 2)是否可以解析wget输出,以便每N个数据点或N秒将数据保存在文件中?
The client-server method seems like the way to go, but the example above seems to work with only using a web browser, or a single command line function. 客户端-服务器方法似乎很可行,但是上面的示例似乎仅在使用Web浏览器或单个命令行功能时才有效。 This might seem a bit easier to use, for some applications.
对于某些应用程序,这似乎更易于使用。
This is a simple application, just being used to dump data from a set of sensors. 这是一个简单的应用程序,仅用于从一组传感器中转储数据。
In my research, I've also seen UDP client-server: 在我的研究中,我还看到了UDP客户端服务器:
http://www.toptechboy.com/tutorial/python-with-arduino-lesson-16-simple-client-server-configuration-over-ethernet/ http://www.toptechboy.com/tutorial/python-with-arduino-lesson-16-simple-client-server-configuration-over-ethernet/
Didn't know if there was a preferred way of doing this. 不知道是否有这样做的首选方法。
If you're throwing stuff over the network with no specific client in mind, I think UDP might be a better option. 如果您在不考虑特定客户端的情况下在网络上扔东西,我认为UDP可能是一个更好的选择。
As for limiting file size, I suggest using logrotate like this answer suggests - https://unix.stackexchange.com/questions/17209/how-to-limit-log-file-size-using 至于限制文件大小,我建议使用logrotate这样的答案-https: //unix.stackexchange.com/questions/17209/how-to-limit-log-file-size-using
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.