-->

我要如何RTC发送时间戳网站在GET请求? 使用的Arduino(how do i send t

2019-10-29 13:13发布

嗨,我一直在试图从我的Arduino的数据发送到我的ASP.Net网站,并获得了成功,直到我试图发送一个时间戳作为GET请求的变量。 我认为它具有财产以后做分隔的值,但正斜杠,当我发送不同势符号就像一个“ - ”我会得到相同的结果(没有数据保存)

编辑:对不起它不是正斜杠! 这是因为asp.net预计:01/01/01 1时01分01秒和我发送1/1/1 1:1:1。 所以我需要弄清楚,如果需要与零面前如何发送

到目前为止我的代码(发送部分)

void sendLightData() {
  DateTime now = rtc.now();
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET /LightData.aspx?uname=");
    client.print(userName);
    client.print("&pword=");
    client.print(password);
    client.print("&LStatus=");
    client.print(lightStatus);
    client.print("&LHeight=9&");
    client.print("timestamp=");
    client.print(now.day(), DEC);
    client.print("/");
    client.print(now.month(), DEC);
    client.print("/");
    client.print(now.year(), DEC);
    client.print("%20");
    client.print(now.hour(), DEC);
    client.print(":");
    client.print(now.minute(), DEC);
    client.print(":");
    client.print(now.second(), DEC); 
    client.println(" HTTP/1.1");
    client.println("Host: www.auntieagie.eu");
    client.println("Connection: close");
    client.println();
    // this works if entered into a browser (trying to replicate in arduino) http://auntieagie.eu/LightData.aspx?uname=test&pword=t&LStatus=1&LHeight=2&timestamp=21/02/2014%2001:01:01
  } 

任何帮助或在正确的方向点将是巨大的

Answer 1:

你需要URL编码之类的东西/

%2F

所以27/2/2014将是27%2F2%2F2014



Answer 2:

只是URL编码全日期:

...
client.print("timestamp=");
client.print(URLEncode(String(now)));
...

Helper方法:

/**
 * URL Encode a string.
 * 
 * Based on http://www.icosaedro.it/apache/urlencode.c
 *
 */
String URLEncode(const char* msg)
{
    const char *hex = "0123456789abcdef";
    String encodedMsg = "";

    while (*msg!='\0'){
        if( ('a' <= *msg && *msg <= 'z')
                || ('A' <= *msg && *msg <= 'Z')
                || ('0' <= *msg && *msg <= '9') ) {
            encodedMsg += *msg;
        } else {
            encodedMsg += '%';
            encodedMsg += hex[*msg >> 4];
            encodedMsg += hex[*msg & 15];
        }
        msg++;
    }
    return encodedMsg;
}


文章来源: how do i send timestamp from RTC to website in a Get request? using arduino