STM32 Ethernet experimental applications

Discussions about the STM32generic core
Post Reply
ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

STM32 Ethernet experimental applications

Post by ChrisMicro » Sat Aug 12, 2017 9:44 pm

Because danieleff enabled the ethernet on the STM32F756 discovery, I was thinking what could be done with it.

The first idea was to access this website and displaying the latest topics. I didn't succeed because I have not really succeed because the server delivered only the frame but not the content.
So i tried another thing. The following program prints the active uses in the forum to the serial line of the board.

Code: Select all

// Example for the onboard ethernet connector
//
// Install https://github.com/stm32duino/LwIP
//     and https://github.com/stm32duino/STM32Ethernet
//
// If they are empty, install the work in progress versions using git:
//    cd <your arduino library folder>
//    git clone https://github.com/fprwi6labs/LwIP.git
//    cd LwIP
//    git checkout LwIP_src
//
//    cd ..
//    git clone https://github.com/fprwi6labs/STM32Ethernet.git
//    cd STM32Ethernet
//    git checkout add_src
//
//
// For more examples, check the STM32Ethernet examples folder

#include <LwIP.h>
#include <STM32Ethernet.h>

EthernetClient client;

// random MAC address
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

void setup() {
  Serial.begin(115200);

  Serial.println("Connecting to Ethernet");

  if (!Ethernet.begin(mac)) {
    Serial.println("ERROR: Could not connect to ethernet!");

    while (1);
  }

  Serial.println("Connecting to www.stm32duino.com");

  //if (!client.connect("example.com", 80)) {
  if (!client.connect("www.stm32duino.com", 80)) {

    Serial.println("ERROR: Could not connect to www.stm32duino.com!");

    while (1);
  }

  Serial.println("Connected, sending request");

  client.println("GET / HTTP/1.1");

  client.println("Host: www.stm32duino.com");
  client.println("User-Agent: Mozilla//5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko//20100101 Firefox//54.0");
  client.println("Accept: text//html,application//xhtml+xml,application//xml;q=0.9,*//*;q=0.8");
  client.println("Accept-Language: en-US,en;q=0.5");
  //client.println("Accept-Encoding: gzip, deflate");
  client.println("Cookie: phpbb3_4im1j_u=1; phpbb3_4im1j_k=; ");
  client.println("DNT: 1");
  client.println("Connection: keep-alive");
  client.println("Upgrade-Insecure-Requests: 1");

  client.println();
  client.flush();

  Serial.println("Request sent, printing response");
}

String str;
boolean flag = false;
void loop() {

  if (client.available()) {
    char c = client.read();

    if (c != '>')str += c;
    else
    {
      if (str.indexOf("users online") > 0)
      {
        flag=true;
        Serial.print("====> ");
        Serial.println(str);
      }
      str = "";

    }
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    while (1);
  }
}

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32 Ethernet experimental applications

Post by ChrisMicro » Fri Aug 18, 2017 1:58 pm

I've made a ethernet picture frame out of the STM32F7 disco.
The pictures can be transmitted by a java-udp-sender program and they are displayed on the STM32F7 disovery.

The Moire-effect in the picture is somehow coming due to my camera. In reality the picture is much better.
Image

Post Reply