簡體   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