Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ethernet and requests
#1
Hello!

I can't figure out the ethernet in arduino ide.
I need to get data from an http/https web page.

Help me, please!
Reply
#2
this is ethernet UDP arduino demo code for KC868-A8: https://www.kincony.com/forum/showthread.php?tid=1608
Reply
#3
(08-20-2024, 12:01 PM)admin Wrote: this is ethernet UDP arduino demo code for KC868-A8: https://www.kincony.com/forum/showthread.php?tid=1608

I've seen this code. It didn't help me. I want to access Internet sites and get the contents of the pages.
Reply
#4
that you should create a cloud server, make server program, let relay board connect to cloud server by MQTT.
Reply
#5
(08-21-2024, 12:48 PM)admin Wrote: that you should create a cloud server, make server program, let relay board connect to cloud server by MQTT.

I found this code, but it not working. help me please!
====
PHP Code:
/*
  Kincony KC868-A8
  Ethernet example
*/

#include <ETH.h>
#include <SPI.h>

#define ETH_CLK_MODE    ETH_CLOCK_GPIO17_OUT
#define ETH_POWER_PIN   -1
#define ETH_TYPE        ETH_PHY_LAN8720
#define ETH_ADDR        0
#define ETH_MDC_PIN     23
#define ETH_MDIO_PIN    18
#define NRST            5

static bool eth_connected false;

void WiFiEvent(WiFiEvent_t event) {
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      ETH.setHostname("esp32-ethernet");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: "); Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");  Serial.print(ETH.localIP());
      if (ETH.fullDuplex()) {Serial.print(", FULL_DUPLEX");}
      Serial.print(", "); Serial.print(ETH.linkSpeed()); Serial.println("Mbps");
      eth_connected true;
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected false;
      break;
    case SYSTEM_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected false;
      break;
    default:
      break;
  }
// WiFiEvent( )

void testClient(const char *hostuint16_t port) {
  Serial.print("\nconnecting to "); Serial.println(host);

  WiFiClient client;
  if (!client.connect(hostport)) {
    Serial.println("connection failed");
    return;
  }
 
  client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n"host);
  while (client.connected() && !client.available());
  while (client.available()) {
    Serial.write(client.read());
  }

  Serial.println("closing connection\n");
  client.stop();
}

void setup() {
  Serial.begin(115200);
  Serial.println(F("Start Kincony KC868-A8 Ethernet example..."));

  WiFi.onEvent(WiFiEvent);

  pinMode(NRSTOUTPUT);
  digitalWrite(NRST0); delay(200);
  digitalWrite(NRST1); delay(200);
  digitalWrite(NRST0); delay(200);
  digitalWrite(NRST1);

  ETH.begin(ETH_ADDRETH_POWER_PINETH_MDC_PINETH_MDIO_PINETH_TYPEETH_CLK_MODE);
}

void loop() {
  if (eth_connected) {
    testClient("baidu.com"80);
  }
  delay(10000);

Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)