Arduino&以太网模块ether.tcpSend无法将数据存储到数据库(通过PHP GET请求)

时间:2016-09-18 01:31:07

标签: arduino

我想通过PHP(使用GET请求)将数据从我的Arduino发送到数据库

我已经测试了我的PHP和成功存储在数据库中的数据

但是当我想实现我的arduino时,数据不会存储到数据库

我正在使用: - Arduino UNO - 以太网模块ENC28J60 - IP地址DHCP(成功获取IP)

这是我的arduino代码

#include <SPI.h>
#include <EtherCard.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield

#define PATH "/bonbit/firebaseTest.php"

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
int totalCount = 1;

const char website[] PROGMEM = "maballo.net";

byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;

void setup() {
  Serial.begin(9600);
  Serial.println("\n[getDHCPandDNS]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");

  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("My IP: ", ether.myip);
  // ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
    Serial.println("Sending Data..");
    ether.packetLoop(ether.packetReceive());

    if (millis() > timer) {
      timer = millis() + 10000;

      byte sd = stash.create();
      stash.print("arduino_data=");
      stash.print(totalCount);
      stash.save();

      // generate the header with payload - note that the stash size is used,
      // and that a "stash descriptor" is passed in as argument using "$H"
      Stash::prepare(PSTR("GET http://$F/$F.csv HTTP/1.0" "\r\n"
                          "Host: $F" "\r\n"
                          "Content-Length: $D" "\r\n"
                          "\r\n"
                          "$H"),
              website, PSTR(PATH), website, stash.size(), sd);

      // send the packet - this also releases all stash buffers once done
      ether.tcpSend();
    }

    totalCount++;
    delay(3000);
}

0 个答案:

没有答案