Feather Ethernet troubles

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Feather Ethernet troubles

Post by LukeR »

I am working on a project that uses a feather connected with a Raspberry pi over Ethernet. The feather reads temperature from an array of thermistors and sends them to the RPi. The feather will eventually control a fan via a relay, but I haven't gotten that far yet.

Here is the server (Raspberry pi 3B+) python code: https://github.com/InventerBots/Green-h ... /server.py

Code: Select all

import math
import socket

HOST = '0.0.0.0' # server IP
PORT = 10004

RELAY_ON=bytes(1)
RELAY_OFF=bytes(0)

tempRaw=0

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  s.bind((HOST, PORT))
  s.listen()
  conn, addr = s.accept()
  with conn:
    print('Connected by', addr)
    while True:
      #--- temperature calculations ---#
      # tempK=1/((1/298.15)+(1/3977)*math.log((10000/(1023/int(conn.recv(1023))-1))/10000))
      # tempF=(tempK-273.15)*(9/5)+32
      # print("Receved: ", tempF)
      data=int(conn.recv(1023))
      x=0
      if data < 10:
        x=data
      
      #print(x)
      tempRaw[x]=data
      print("sensor: ",x)
      print(tempRaw[x])

      #--- fan control ---#
      # if tempF>80 :
      #   conn.send(RELAY_ON)
      #   print("on")
      # else :
      #   conn.send(RELAY_OFF)
      #   print("off")
I don't really have any code for the feather yet, nothing I have tried has worked. I have read most of the CircuitPython Wiznet5k, socket, and socket pool documentation.

The project uses an Adafruit feather Ethernet add-on board and a feather M4 express running the latest firmware, and a network switch connecting everything together with Ethernet.

I do have the project somewhat working on an Arduino uno, but I ran into some architecture issues.
https://github.com/InventerBots/Green-h ... Client.ino

Any help or constrictive criticism will be appreciated.

User avatar
freddyboomboom
 
Posts: 267
Joined: Wed Feb 16, 2022 7:55 pm

Re: Feather Ethernet troubles

Post by freddyboomboom »

0.0.0.0 is not an IP address I've ever seen used before, and I'm not sure it's allowed to be used per the Ethernet specifications.

You could use a variety of the "private addresses" in the IP address space. Commonly 192.168.x.x are used, but the 10.x.x.x range is commonly used as well. There are some private addresses in the 172.x.x.x space, but you'd have to look those up.

I would set the Pi as 10.1.1.1 and the Feather as 10.1.1.2 and try that. (Subnet mask 255.255.255.0)

User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Re: Feather Ethernet troubles

Post by LukeR »

freddyboomboom wrote:0.0.0.0 is not an IP address I've ever seen used before, and I'm not sure it's allowed to be used per the Ethernet specifications.
It does work with an Arduino and my PC. I should probably change that though.

Here is what I have for the feather code.

Code: Select all

from socket import AF_INET, SOCK_STREAM
import busio
import time
import board
from digitalio import DigitalInOut
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
# import socketpool as pool
import socket

local_IP=(192,168,1,12)
mac=('98','76','B6','12','o9','ab')
host=(192,168,1,220)
port=10004
msg="hello"
cs=DigitalInOut(board.D10)
spi_bus=busio.SPI(board.sck, MOSI=board.MOSI, MISO=board.MISO)

eth=WIZNET5K(spi_bus, cs,reset=None, is_dhcp=False,mac=mac, hostname=local_IP)
print("Local IP: ", eth.pretty_ip(local_IP))
print("Local MAC: ", eth.pretty_mac(mac))
# eth.socket_open(port)
# eth.socket_connect([host, port])

User avatar
freddyboomboom
 
Posts: 267
Joined: Wed Feb 16, 2022 7:55 pm

Re: Feather Ethernet troubles

Post by freddyboomboom »

I don't have an Ethernet Featherwing, so I don't know anything about that, but there would need to be something on the network for it to talk to at 192.168.1.220.

It probably won't talk to 0.0.0.0 because that's in a different network and the 192.168.x.x addresses are not routable. But I'm not a network engineer, I just know a bit about networking from years of playing with them.

Make sure you are specifying the MAC address of your Ethernet MAC. Not all MACs can spoof a different address, and you usually have to jump through some sort of hoops to do so.

User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Re: Feather Ethernet troubles

Post by LukeR »

The Raspberry Pi's IP is not 0.0.0.0, it is 192.168.1.220
Untitled.png
Untitled.png (18.5 KiB) Viewed 242 times
As I understand from my research, binding an address of 0.0.0.0 to a port just ignores the host IP, it may be bad programming but it does work. The Arduino connects to the Raspberry Pi, I can run a simple test client on my PC and it connects as intended. The main reason for switching from an Arduino to a Feather is for python programming and for the increased computing power.

The Raspberry Pi server is working as intended at this time.

User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Re: Feather Ethernet troubles

Post by LukeR »

I have a basic understanding of ethernet networks, the only thing I need help with at this time is getting the feather to connect to my server without using the internet. The only examples that I have found require an internet connection.

User avatar
freddyboomboom
 
Posts: 267
Joined: Wed Feb 16, 2022 7:55 pm

Re: Feather Ethernet troubles

Post by freddyboomboom »

192.168.1.220 and 192.168.1.12 are on the same network, so as long as you have the correct MAC address in the code on the Feather and have the correct subnet mask, they should work.

You do seem to be importing socket twice.

Does the test code from the Learn Guide work? https://learn.adafruit.com/ethernet-for ... thon/usage


User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Re: Feather Ethernet troubles

Post by LukeR »

freddyboomboom wrote:Does the test code from the Learn Guide work? https://learn.adafruit.com/ethernet-for ... thon/usage
I looked through that example again and made a little progress. That program will not work for me as I do not have an internet connection available, nor do I have a website URL to host the Feather. I also need static IP, not DHCP.

Here is as far as I have gotten so far.
https://github.com/InventerBots/GreenHo ... 83/code.py

Code: Select all

import busio
import time
import board
from digitalio import DigitalInOut
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as wizSocket
import adafruit_requests as requests

local_IP=(192,168,1,12)
mac=('98','76','B6','12','o9','ab')
host=(192,168,1,220)
port=10004
msg="hello"
cs=DigitalInOut(board.D10)
spi_bus=busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

eth=WIZNET5K(spi_bus, cs, is_dhcp=False, hostname=local_IP)

requests.set_socket(wizSocket, eth)

User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Re: Feather Ethernet troubles

Post by LukeR »

I made a little progress, I think I figured out how to connect to a remote host. The only problem I have is I can not change the local IP from 0.0.0.0 to 192.168.1.12.
Here is my code:
https://github.com/InventerBots/GreenHo ... fb/code.py

Code: Select all

import busio
import time
import board
from digitalio import DigitalInOut
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as wizSocket
import adafruit_requests as requests

local_IP=str(b'192.168.1.12')
mac=(98, 76, 19, 12, 9, 253) # 98:76:B6:12:09:ab
host=(192,168,1,220)
port=10004

addr='192.168.1.220:10004'

msg="hello"
cs=DigitalInOut(board.D10)
spi_bus=busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

eth=WIZNET5K(spi_bus, cs, None, False, mac, local_IP)
requests.set_socket(wizSocket, eth)

print("Chip Version:", eth.chip)
print("MAC Address:", [hex(i) for i in eth.mac_address])
print("My IP address is:", eth.pretty_ip(eth.ip_address))

eth.socket_connect(0, host, port)


User avatar
blakebr
 
Posts: 989
Joined: Tue Apr 17, 2012 6:23 pm

Re: Feather Ethernet troubles

Post by blakebr »

Tracking

User avatar
LukeR
 
Posts: 14
Joined: Sun May 15, 2022 2:56 pm

Re: Feather Ethernet troubles

Post by LukeR »

I have found a workaround for my issue by using a DHCP server on my Raspberry Pi. As far as I can tell, Circuitpython does not support static IP but DHCP can be disabled. Am I missing something or has static IP not been fully implemented yet?

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”