代码之家  ›  专栏  ›  技术社区  ›  Lucas

Arduino Uno+ENC28J60+domoticz

  •  0
  • Lucas  · 技术社区  · 3 年前

    我想向domoticz发送请求: http://192.168.1.204:8084/json.htm?type=command&param=udevice&idx=3&svalue=5000 (domoticz设备中的地址测试和更改值) 我用了一个基本的例子把arduino连接到网络上。 它从DHCP获得了正确的IP地址(我可以ping它),但没有发送任何带有此代码的请求(使用WireShark检查-仅从Arduino发送DHCP请求)。 我也尝试过Arduino作为http服务器工作,它正在工作,所以在硬件方面看起来还可以。ENC28J60连接到PIN10+ISCP端口(不像大多数手册中那样在引脚11-13上工作) 我做错了什么?应该有其他命令发送请求吗? 很抱歉,如果这是一个非常基本的问题,但我正在开始我的编程方式。这是我的第一个问题,通常搜索这个网站已经足够了。。

    // Demo using DHCP and DNS to perform a web client request.
    // 2011-06-08 <[email protected]>
    //
    // License: GPLv2
    
    #include <EtherCard.h>
    
    // ethernet interface mac address, must be unique on the LAN
    static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
    
    byte Ethernet::buffer[700];
    static uint32_t timer;
    
    const char website[] PROGMEM = "192.168.1.204:8084";
    
    // called when the client request is complete
    static void my_callback (byte status, word off, word len) {
      Serial.println(">>>");
      Ethernet::buffer[off+300] = 0;
      Serial.print((const char*) Ethernet::buffer + off);
      Serial.println("...");
    }
    
    void setup () {
      Serial.begin(57600);
      Serial.println(F("\n[webClient]"));
    
      // Change 'SS' to your Slave Select pin, if you arn't using the default pin
      if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
        Serial.println(F("Failed to access Ethernet controller"));
      if (!ether.dhcpSetup())
        Serial.println(F("DHCP failed"));
    
      ether.printIp("IP:  ", ether.myip);
      ether.printIp("GW:  ", ether.gwip);
      ether.printIp("DNS: ", ether.dnsip);
    
    #if 1
      // use DNS to resolve the website's IP address
      if (!ether.dnsLookup(website))
        Serial.println("DNS failed");
    #elif 2
      // if website is a string containing an IP address instead of a domain name,
      // then use it directly. Note: the string can not be in PROGMEM.
      char websiteIP[] = "192.168.1.204:6144";
      ether.parseIp(ether.hisip, websiteIP);
    //#else
    //  // or provide a numeric IP address instead of a string
    //  byte hisip[] = { 192,168,1,1 };
    //  ether.copyIp(ether.hisip, hisip);
    #endif
    
      ether.printIp("SRV: ", ether.hisip);
    }
    
    void loop () {
      ether.packetLoop(ether.packetReceive());
    
      if (millis() > timer) {
        timer = millis() + 5000;
        Serial.println();
        Serial.print("<<< REQ ");
        ether.browseUrl(PSTR("/json.htm?type=command&param=udevice&idx=3&svalue="), "5000", website, my_callback);
        Serial.println("after browseurl");
      }
    }
    
    0 回复  |  直到 3 年前
        1
  •  0
  •   Lucas    3 年前

    我已经将parseip从if语句中移除,现在我有来自服务器的响应,但现在是400错误请求(192.168.1.204是Synology服务器,domoticz在8084端口上工作)。 我的命令是: ether.browseUrl(PSTR(“:8084/json.htm?type=command&param=udevice&idx=3&svalue=400”),“”,网站,my_callback);

    其中char websiteIP[]=“192.168.1.204”; (我也尝试过从PSTR中删除端口的网站IP“192.168.1.204:8084”)

    当我在笔记本电脑上使用wireshark时,我看不到任何流量(我只能看到ping),所以我不知道到底发送了什么。 我需要发送 http://192.168.1.204:8084/json.htm?type=command&param=udevice&idx=3&svalue=400 -我认为browseUrl命令的格式在我的情况下是不正确的

        2
  •  0
  •   Lucas    3 年前

    解决了! 我已将数据包转发到我的笔记本电脑上。 然后我在wireshark中发现它仍在使用80端口。 我添加了行: ether.hisport=8084; 它解决了我的问题!

    推荐文章