繁体   English   中英

来自Arduino的数据通过以太网和wget代替python

[英]Data from Arduino over Ethernet and wget, instead of python

似乎已经在几个地方讨论了通过以太网为数据提供服务的Arduino主题:

1) Arduino以太网通讯

2) 使用arduino客户端/ python服务器通过以太网转储数据

我最喜欢的方式是在第一篇文章中提到的Arduino WebClient选项:

https://www.arduino.cc/en/Tutorial/WebClient

第二篇文章涉及一些Python(2.7),但似乎问题并未解决。 我还想知道使用wget是否更容易。

如果您将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;
  }
}

...您可以使用“ wget 192.168.3.50”获取数据,该数据转储到文件中(默认为index.html)。

这不是典型的客户机/服务器程序,程序在其中询问信息,然后将其返回。 服务器只是将数据转储出去,您可以将Web浏览器指向IP地址,或者如上所示,使用wget。

当您“设置并忘记” wget命令时,数据记录得很好。 我刚刚进行了1.75+小时的测试,并获得了60K +条线路(每100毫秒一次),系统正常工作。

我注意到,如果我停止“ wget”命令,然后重新启动它,几次后,wget进程将挂起,并且我必须重置Arduino。

完整的客户端-服务器程序似乎是一种更好的方法:

https://giovanniorgantini.wordpress.com/2015/03/14/getting-data-over-the-internet-with-arduino/

...并且我现在将继续研究(原始客户端在C中,如果有人可以将我指向一个简单的python-Arduino程序,否则,我将在看一个简单的python客户端),但我想知道:

1)为什么停止'wget'(control-C)会在重新启动wget进程时导致问题,系统在此挂起:

user @ machine:$ wget 192.168.3.50 --2018-02-12 19:58:54-- http://192.168.3.50/正在连接到192.168.3.50:80 ...

停止数据流的一个原因是停止测试或以编程方式启动另一个数据文件的时间。

2)是否可以解析wget输出,以便每N个数据点或N秒将数据保存在文件中?

客户端-服务器方法似乎很可行,但是上面的示例似乎仅在使用Web浏览器或单个命令行功能时才有效。 对于某些应用程序,这似乎更易于使用。

这是一个简单的应用程序,仅用于从一组传感器中转储数据。

在我的研究中,我还看到了UDP客户端服务器:

http://www.toptechboy.com/tutorial/python-with-arduino-lesson-16-simple-client-server-configuration-over-ethernet/

不知道是否有这样做的首选方法。

如果您在不考虑特定客户端的情况下在网络上扔东西,我认为UDP可能是一个更好的选择。

至于限制文件大小,我建议使用logrotate这样的答案-https: //unix.stackexchange.com/questions/17209/how-to-limit-log-file-size-using

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM