Getting correct IP address but not sending code

131 Views Asked by At

I would like to send request to domoticz: http://192.168.1.204:8084/json.htm?type=command&param=udevice&idx=3&svalue=5000 (address tested and changing value in domoticz device) I've used basic example to connect arduino to the network. It's getting correct IP address from DHCP (I can ping it), but not sending any request with this code (checked with WireShark- only DHCP requests sent from Arduino). I've also tried Arduino working as http server and it's working, so looks ok on hardware side. ENC28J60 is connected to PIN10 + ISCP port (doesn't work on pins 11-13 as in most manuals) What am I doing wrong? should be any other command to send request? Sorry if it's very basic question, but I'm on begin of my programming way. It's my first question, usually searching this website has been enough..

// 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");
  }
}
2

There are 2 best solutions below

0
On

Solved! I've forwarded packets to my laptop. Then I found in wireshark that it's still using port 80. I've added line: ether.hisport = 8084; it solved my problem!

0
On

I've moved parseip out of if statement and now I have response from server - but now it's 400 Bad request (192.168.1.204 is Synology server with domoticz working on port 8084). my command is: ether.browseUrl(PSTR(":8084/json.htm?type=command&param=udevice&idx=3&svalue=400"),"", website, my_callback);

where char websiteIP[] = "192.168.1.204"; (I've also tried websiteIP "192.168.1.204:8084" with port removed from PSTR )

I can't see any traffic when I'm using wireshark on my laptop (I can see ping's only) - so I don't know what exactly been sent. I need to send http://192.168.1.204:8084/json.htm?type=command&param=udevice&idx=3&svalue=400 - I believe format of browseUrl command is incorrect in my case