Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use? #5

Closed
MRIIOT opened this issue Oct 14, 2024 · 5 comments
Closed

How to use? #5

MRIIOT opened this issue Oct 14, 2024 · 5 comments
Assignees

Comments

@MRIIOT
Copy link

MRIIOT commented Oct 14, 2024

Here is my setup, but so far I do not see messages at Linux or ESP end...
I am using the changes from here: #4
I confirmed that I can send/receive between two ESPs.

sudo apt install git python3-venv net-tools

git clone https://github.com/ChuckMash/ESPythoNOW.git
cd ESPythoNOW
python3 -m venv venv
source venv/bin/activate
pip install scapy
sudo bash prep.sh wlo2 8

# create sniff.py

cp venv/bin/python3 venv/bin/python_netraw
sudo chown $USER venv/bin/python_netraw
chmod -x,u+x venv/bin/python_netraw
sudo setcap cap_net_raw=eip venv/bin/python_netraw
python_netraw sniff.py

sniff.py

from ESPythoNOW import *
import time

def callback(from_mac, to_mac, msg):
  print("ESP-NOW message from %s to %s: %s" % (from_mac, to_mac, msg))

espnow = ESPythoNow(interface="wlo2", accept_all=True, callback=callback)
espnow.start()
print("running")
# input() # Run until enter is pressed

while True:
        msg=b'\x01\x10'
        espnow.send("08:d1:f9:54:00:cc", msg)
        time.sleep(3)

linux ip a show:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 00:e0:4c:01:b8:d6 brd ff:ff:ff:ff:ff:ff
3: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:e0:4c:01:b8:d7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.206/24 brd 192.168.111.255 scope global dynamic noprefixroute enp3s0
       valid_lft 404sec preferred_lft 404sec
    inet6 fe80::2e0:4cff:fe01:b8d7/64 scope link
       valid_lft forever preferred_lft forever
4: wlo2: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state DORMANT group default qlen 1000
    link/ieee802.11/radiotap 34:7d:f6:b5:6f:a3 brd ff:ff:ff:ff:ff:ff
    altname wlp0s12f0

ESP script:

import network
import espnow

_esp_now_peer = b'\x34\x7d\xf6\xb5\x6f\xa3'

sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.disconnect()
now = espnow.ESPNow()
now.active(True)
now.add_peer(_esp_now_peer)
now.send(_esp_now_peer, "hello from SHARC")
print('espnow: hello sent to peer')

while True:
  host, msg = now.recv()
  if msg:
    print(f'espnow: received {msg} from {host}')
@ChuckMash
Copy link
Owner

I assume this is micropython on the ESP side?
You may need to set the WiFi channel to channel 8 on the ESP, since it was specified with prep.sh on the Linux side.

@MRIIOT
Copy link
Author

MRIIOT commented Oct 14, 2024

Yes, this is MP on ESP side.

I set channel to 8, and ESP<->ESP is OK, but ESP<->Linux shows no data.

ESP1

import network
import espnow

_esp_now_peer = b'\x34\x7d\xf6\xb5\x6f\xa3'

sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.disconnect()
sta.config(channel=8)
now = espnow.ESPNow()
now.active(True)
now.add_peer(_esp_now_peer)
now.send(_esp_now_peer, "hello from SHARC")
print('espnow: hello sent to peer')

while True:
  host, msg = now.recv()
  if msg:
    print(f'espnow: received {msg} from {host}')

ESP2

import network
import espnow
import utime as time

# _esp_now_peer = b'\x34\x7d\xf6\xb5\x6f\xa3'
_esp_now_peer = b'\xff\xff\xff\xff\xff\xff'

sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.disconnect()
sta.config(channel=8)
now = espnow.ESPNow()
now.active(True)
now.add_peer(_esp_now_peer)


while True:
  host, msg = now.recv(0)
  if msg:
    print(f'espnow: received {msg} from {host}')

  now.send(_esp_now_peer, "hello from WALTER")
  time.sleep(1)

@ChuckMash
Copy link
Owner

ChuckMash commented Oct 14, 2024

This is early on in the projects development, so bringing these issues up is very valuable, thank you.

Other things to consider:

Does the wlo2 chipset/driver support monitor mode?

Any output from prep.sh when you ran it?

Does scapy have root access to the interface? (could be https://stackoverflow.com/questions/44345689/sudo-scapy-not-working-on-virtualenv)

I am unfamiliar with ESP-NOW on micropython, maybe you could initially try simple_send_and_receive_ESP8266.ino or simple_send_and_receive_ESP32.ino

@MRIIOT
Copy link
Author

MRIIOT commented Oct 14, 2024

It appears that Intel 9560d2w does NOT support monitor based on Internet, but running iw does show monitor is supported. I will get an AR9271 adapter anyways.

Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * monitor
		 * P2P-client
		 * P2P-GO
		 * P2P-device

I do not know if scapy has root access to the interface. Would assigning CAP_NET_RAW have the same effect?

cp venv/bin/python3 venv/bin/python_netraw
sudo chown $USER venv/bin/python_netraw
chmod -x,u+x venv/bin/python_netraw
sudo setcap cap_net_raw=eip venv/bin/python_netraw
python_netraw sniff.py

Intel

iw phy phy0 info
Wiphy phy0
	wiphy index: 0
	max # scan SSIDs: 20
	max scan IEs length: 422 bytes
	max # sched scan SSIDs: 20
	max # match sets: 11
	Retry short limit: 7
	Retry long limit: 4
	Coverage class: 0 (up to 0m)
	Device supports RSN-IBSS.
	Device supports AP-side u-APSD.
	Device supports T-DLS.
	Supported Ciphers:
		* WEP40 (00-0f-ac:1)
		* WEP104 (00-0f-ac:5)
		* TKIP (00-0f-ac:2)
		* CCMP-128 (00-0f-ac:4)
		* GCMP-128 (00-0f-ac:8)
		* GCMP-256 (00-0f-ac:9)
		* CMAC (00-0f-ac:6)
		* GMAC-128 (00-0f-ac:11)
		* GMAC-256 (00-0f-ac:12)
	Available Antennas: TX 0x3 RX 0x3
	Configured Antennas: TX 0x3 RX 0x3
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * monitor
		 * P2P-client
		 * P2P-GO
		 * P2P-device
	Band 1:
		Capabilities: 0x19ef
			RX LDPC
			HT20/HT40
			SM Power Save disabled
			RX HT20 SGI
			RX HT40 SGI
			TX STBC
			RX STBC 1-stream
			Max AMSDU length: 7935 bytes
			DSSS/CCK HT40
		Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
		Minimum RX AMPDU time spacing: 4 usec (0x05)
		HT Max RX data rate: 300 Mbps
		HT TX/RX MCS rate indexes supported: 0-15
		Bitrates (non-HT):
			* 1.0 Mbps
			* 2.0 Mbps (short preamble supported)
			* 5.5 Mbps (short preamble supported)
			* 11.0 Mbps (short preamble supported)
			* 6.0 Mbps
			* 9.0 Mbps
			* 12.0 Mbps
			* 18.0 Mbps
			* 24.0 Mbps
			* 36.0 Mbps
			* 48.0 Mbps
			* 54.0 Mbps
		Frequencies:
			* 2412.0 MHz [1] (22.0 dBm)
			* 2417.0 MHz [2] (22.0 dBm)
			* 2422.0 MHz [3] (22.0 dBm)
			* 2427.0 MHz [4] (22.0 dBm)
			* 2432.0 MHz [5] (22.0 dBm)
			* 2437.0 MHz [6] (22.0 dBm)
			* 2442.0 MHz [7] (22.0 dBm)
			* 2447.0 MHz [8] (22.0 dBm)
			* 2452.0 MHz [9] (22.0 dBm)
			* 2457.0 MHz [10] (22.0 dBm)
			* 2462.0 MHz [11] (22.0 dBm)
			* 2467.0 MHz [12] (22.0 dBm)
			* 2472.0 MHz [13] (22.0 dBm)
			* 2484.0 MHz [14] (disabled)
	Band 2:
		Capabilities: 0x19ef
			RX LDPC
			HT20/HT40
			SM Power Save disabled
			RX HT20 SGI
			RX HT40 SGI
			TX STBC
			RX STBC 1-stream
			Max AMSDU length: 7935 bytes
			DSSS/CCK HT40
		Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
		Minimum RX AMPDU time spacing: 4 usec (0x05)
		HT Max RX data rate: 300 Mbps
		HT TX/RX MCS rate indexes supported: 0-15
		VHT Capabilities (0x039071f6):
			Max MPDU length: 11454
			Supported Channel Width: 160 MHz
			RX LDPC
			short GI (80 MHz)
			short GI (160/80+80 MHz)
			TX STBC
			SU Beamformee
			MU Beamformee
		VHT RX MCS set:
			1 streams: MCS 0-9
			2 streams: MCS 0-9
			3 streams: not supported
			4 streams: not supported
			5 streams: not supported
			6 streams: not supported
			7 streams: not supported
			8 streams: not supported
		VHT RX highest supported: 0 Mbps
		VHT TX MCS set:
			1 streams: MCS 0-9
			2 streams: MCS 0-9
			3 streams: not supported
			4 streams: not supported
			5 streams: not supported
			6 streams: not supported
			7 streams: not supported
			8 streams: not supported
		VHT TX highest supported: 0 Mbps
		VHT extended NSS: supported
		Bitrates (non-HT):
			* 6.0 Mbps
			* 9.0 Mbps
			* 12.0 Mbps
			* 18.0 Mbps
			* 24.0 Mbps
			* 36.0 Mbps
			* 48.0 Mbps
			* 54.0 Mbps
		Frequencies:
			* 5180.0 MHz [36] (22.0 dBm)
			* 5200.0 MHz [40] (22.0 dBm)
			* 5220.0 MHz [44] (22.0 dBm)
			* 5240.0 MHz [48] (22.0 dBm)
			* 5260.0 MHz [52] (22.0 dBm) (no IR, radar detection)
			* 5280.0 MHz [56] (22.0 dBm) (no IR, radar detection)
			* 5300.0 MHz [60] (22.0 dBm) (no IR, radar detection)
			* 5320.0 MHz [64] (22.0 dBm) (no IR, radar detection)
			* 5340.0 MHz [68] (disabled)
			* 5360.0 MHz [72] (disabled)
			* 5380.0 MHz [76] (disabled)
			* 5400.0 MHz [80] (disabled)
			* 5420.0 MHz [84] (disabled)
			* 5440.0 MHz [88] (disabled)
			* 5460.0 MHz [92] (disabled)
			* 5480.0 MHz [96] (disabled)
			* 5500.0 MHz [100] (22.0 dBm) (no IR, radar detection)
			* 5520.0 MHz [104] (22.0 dBm) (no IR, radar detection)
			* 5540.0 MHz [108] (22.0 dBm) (no IR, radar detection)
			* 5560.0 MHz [112] (22.0 dBm) (no IR, radar detection)
			* 5580.0 MHz [116] (22.0 dBm) (no IR, radar detection)
			* 5600.0 MHz [120] (22.0 dBm) (no IR, radar detection)
			* 5620.0 MHz [124] (22.0 dBm) (no IR, radar detection)
			* 5640.0 MHz [128] (22.0 dBm) (no IR, radar detection)
			* 5660.0 MHz [132] (22.0 dBm) (no IR, radar detection)
			* 5680.0 MHz [136] (22.0 dBm) (no IR, radar detection)
			* 5700.0 MHz [140] (22.0 dBm) (no IR, radar detection)
			* 5720.0 MHz [144] (22.0 dBm) (no IR, radar detection)
			* 5745.0 MHz [149] (22.0 dBm)
			* 5765.0 MHz [153] (22.0 dBm)
			* 5785.0 MHz [157] (22.0 dBm)
			* 5805.0 MHz [161] (22.0 dBm)
			* 5825.0 MHz [165] (22.0 dBm)
			* 5845.0 MHz [169] (disabled)
			* 5865.0 MHz [173] (disabled)
			* 5885.0 MHz [177] (disabled)
			* 5905.0 MHz [181] (disabled)
	Supported commands:
		 * new_interface
		 * set_interface
		 * new_key
		 * start_ap
		 * new_station
		 * new_mpath
		 * set_mesh_config
		 * set_bss
		 * authenticate
		 * associate
		 * deauthenticate
		 * disassociate
		 * join_ibss
		 * join_mesh
		 * remain_on_channel
		 * set_tx_bitrate_mask
		 * frame
		 * frame_wait_cancel
		 * set_wiphy_netns
		 * set_channel
		 * tdls_mgmt
		 * tdls_oper
		 * start_sched_scan
		 * probe_client
		 * set_noack_map
		 * register_beacons
		 * start_p2p_device
		 * set_mcast_rate
		 * connect
		 * disconnect
		 * channel_switch
		 * set_qos_map
		 * add_tx_ts
		 * set_multicast_to_unicast
	WoWLAN support:
		 * wake up on disconnect
		 * wake up on magic packet
		 * wake up on pattern match, up to 20 patterns of 16-128 bytes,
		   maximum packet offset 0 bytes
		 * can do GTK rekeying
		 * wake up on GTK rekey failure
		 * wake up on EAP identity request
		 * wake up on 4-way handshake
		 * wake up on rfkill release
		 * wake up on network detection, up to 11 match sets
	software interface modes (can always be added):
		 * AP/VLAN
		 * monitor
	valid interface combinations:
		 * #{ managed } <= 1, #{ AP, P2P-client, P2P-GO } <= 1, #{ P2P-device } <= 1,
		   total <= 3, #channels <= 2
	HT Capability overrides:
		 * MCS: ff ff ff ff ff ff ff ff ff ff
		 * maximum A-MSDU length
		 * supported channel width
		 * short GI for 40 MHz
		 * max A-MPDU length exponent
		 * min MPDU start spacing
	Device supports TX status socket option.
	Device supports HT-IBSS.
	Device supports SAE with AUTHENTICATE command
	Device supports low priority scan.
	Device supports scan flush.
	Device supports per-vif TX power setting
	P2P GO supports CT window setting
	P2P GO supports opportunistic powersave setting
	Driver supports full state transitions for AP/GO clients
	Driver supports a userspace MPM
	Driver/device bandwidth changes during BSS lifetime (AP/GO mode)
	Device adds DS IE to probe requests
	Device can update TPC Report IE
	Device supports static SMPS
	Device supports dynamic SMPS
	Device supports WMM-AC admission (TSPECs)
	Device supports configuring vdev MAC-addr on create.
	Device supports randomizing MAC-addr in scans.
	Device supports randomizing MAC-addr in sched scans.
	Device supports randomizing MAC-addr in net-detect scans.
	max # scan plans: 2
	max scan plan interval: 65535
	max scan plan iterations: 254
	Supported TX frame types:
		 * IBSS: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * mesh point: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
		 * P2P-device: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
	Supported RX frame types:
		 * IBSS: 0x40 0xb0 0xc0 0xd0
		 * managed: 0x40 0xb0 0xd0
		 * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
		 * AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
		 * mesh point: 0xb0 0xc0 0xd0
		 * P2P-client: 0x40 0xd0
		 * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
		 * P2P-device: 0x40 0xd0
	Supported extended features:
		* [ VHT_IBSS ]: VHT-IBSS
		* [ RRM ]: RRM
		* [ MU_MIMO_AIR_SNIFFER ]: MU-MIMO sniffer
		* [ SCAN_START_TIME ]: scan start timestamp
		* [ BSS_PARENT_TSF ]: BSS last beacon/probe TSF
		* [ BEACON_RATE_LEGACY ]: legacy beacon rate setting
		* [ FILS_STA ]: STA FILS (Fast Initial Link Setup)
		* [ CONTROL_PORT_OVER_NL80211 ]: control port over nl80211
		* [ TXQS ]: FQ-CoDel-enabled intermediate TXQs
		* [ SCAN_MIN_PREQ_CONTENT ]: use probe request with only rate IEs in scans
		* [ EXT_KEY_ID ]: Extended Key ID support
		* [ CONTROL_PORT_NO_PREAUTH ]: disable pre-auth over nl80211 control port support
		* [ DEL_IBSS_STA ]: deletion of IBSS station support
		* [ SCAN_FREQ_KHZ ]: scan on kHz frequency support
		* [ CONTROL_PORT_OVER_NL80211_TX_STATUS ]: tx status for nl80211 control port support
		* [ POWERED_ADDR_CHANGE ]: can change MAC address while up

@ChuckMash ChuckMash self-assigned this Oct 14, 2024
@MRIIOT
Copy link
Author

MRIIOT commented Oct 17, 2024

Works perfect with AR9271.

image

@MRIIOT MRIIOT closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants