Giter VIP home page Giter VIP logo

esp32-simulator's Introduction

This repository contains ESP32 simulator for linux.

How does it work?

ESP-IDF contains small amount of hardware specific code, FreeRTOS and few multi-platform libraries.

This project uses FreeRTOS port for POSIX, LWIP for TCP/IP layer and mbedtls for cryptography functions.

In addition, several useful APIs from esp-idf are implemented eg. logging.

With this project you can write a program, which will be runnable and testable on Linux.

Running

Network

This project requires tun kernel module and configured tap0 interface to work. To configure tap0 run following commands:

sudo ip tuntap add dev tap0 mode tap user `whoami`
sudo ip link set tap0 up
sudo ip addr add 10.0.0.1/24 dev tap0
export PRECONFIGURED_TAPIF=tap0

Simulator can be connected to internet using masquerade. First we need to enable forwarding.

sudo echo 1 > /proc/sys/net/ipv4/ip_forward

Simple nftables forwarding rules:

#!/sbin/nft -f

flush ruleset


table inet filter {
	chain input {
		type filter hook input priority 0; policy drop;
		ct state invalid counter drop
		ct state {established, related} counter accept
		iif lo accept
		iif != lo ip daddr 127.0.0.1/8 counter drop
		iif != lo ip6 daddr ::1/128 counter drop
		ip protocol icmp counter accept
		ip6 nexthdr icmpv6 counter accept
		iifname tap0 accept
	}

	chain forward {
		type filter hook forward priority 0; policy accept;
	}

	chain output {
		type filter hook output priority 0; policy accept;
	}
}


table ip nat {
	chain input {
		type nat hook input priority 0; policy accept;
		ip protocol icmp accept
	}

	chain prerouting {
		type nat hook prerouting priority 0; policy accept;
	}

	chain postrouting {
		type nat hook postrouting priority 100; policy accept;
		ip daddr != 10.0.0.0/24 ip saddr 10.0.0.0/24 masquerade;
	}

	chain output {
		type nat hook output priority 0; policy accept;
	}
}

Using ubuntu

sudo apt install -y git wget flex bison gperf python3 python3-pip python3-setuptools python3-serial python3-click python3-cryptography python3-future python3-pyparsing python3-pyelftools cmake ninja-build ccache libffi-dev libssl-dev libusb-1.0-0
mkdir esp
cd esp
git clone -b release/v5.2 --recursive https://github.com/espressif/esp-idf.git
./esp-idf/install.sh
. ./esp-idf/export.sh
git clone --recursive https://github.com/mireq/esp32-simulator
cd simulator/example
idf.py build
./build/example

Inside docker

docker build -t esp32-simulator .
docker run --cap-add=NET_ADMIN --device /dev/net/tun:/dev/net/tun --name esp32-simulator -v `pwd`:/root/simulator -d esp32-simulator

docker exec -i -t esp32-simulator bash
cd ~/simulator/example
idf.py build
./build/example

esp32-simulator's People

Contributors

mireq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-simulator's Issues

Unknown CMake command "idf_component_register".

Have done all steps as proposed on ubuntu.
Hence calling idf.py build i get error: Unknown CMake command "idf_component_register". Details see below.
Any idea how to get behind that?

  1. Details
    esp32sim@hp2:~/esp/esp32-simulator/example$ idf.py build
    Executing action: all (aliases: build)
    Running ninja in directory /home/esp32sim/esp/esp32-simulator/example/build
    Executing "ninja all"...
    [1/9] Performing configure step for 'linux'
    FAILED: linux-prefix/src/linux-stamp/linux-configure /home/esp32sim/esp/esp32-simulator/example/build/linux-prefix/src/linux-stamp/linux-configure
    cd /home/esp32sim/esp/esp32-simulator/example/build/linux-prefix/src/linux-build && /usr/bin/cmake -DCMAKE_ROOT_BUILD_DIR=/home/esp32sim/esp/esp32-simulator/example/build -DESP_CONFIG_DIR=/home/esp32sim/esp/esp32-simulator/example/build/config -GNinja /home/esp32sim/esp/esp32-simulator/example/simulator && /usr/bin/cmake -E touch /home/esp32sim/esp/esp32-simulator/example/build/linux-prefix/src/linux-stamp/linux-configure
    CMake Error at /home/esp32sim/esp/esp32-simulator/src/freertos/CMakeLists.txt:27 (idf_component_register):
    Unknown CMake command "idf_component_register".

-- Configuring incomplete, errors occurred!
See also "/home/esp32sim/esp/esp32-simulator/example/build/linux-prefix/src/linux-build/CMakeFiles/CMakeOutput.log".
[2/9] cd /home/esp32sim/esp/esp32-simulator/example/build/esp-idf/partition_table && /usr...-E echo "*******************************************************************************"
Partition table binary generated. Contents:


Espressif ESP32 Partition Table

Name, Type, SubType, Offset, Size, Flags

nvs,data,nvs,0x9000,24K,
phy_init,data,phy,0xf000,4K,
factory,app,factory,0x10000,1M,


ninja: build stopped: subcommand failed.
ninja failed with exit code 1

Unable to install under Ubuntu 20.04 LTS 64-bit

I clone the repo and run install, but it fails. I have run the install several times (sometimes it helps); the last few have finished:

XXX:~/git/esp-idf$ ./install.sh
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, xtensa-esp32s2-elf, esp32ulp-elf, esp32s2ulp-elf, openocd-esp32
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Installing Python environment and packages
Creating a new Python environment in /home/XXX/.espressif/python_env/idf4.3_py2.7_env
Installing virtualenv
/usr/bin/python: No module named pip
Traceback (most recent call last):
  File "/home/XXX/git/esp-idf/tools/idf_tools.py", line 1492, in <module>
    main(sys.argv[1:])
  File "/home/XXX/git/esp-idf/tools/idf_tools.py", line 1488, in main
    action_func(args)
  File "/home/XXX/git/esp-idf/tools/idf_tools.py", line 1205, in action_install_python_env
    stdout=sys.stdout, stderr=sys.stderr)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python', '-m', 'pip', 'install', '--user', 'virtualenv']' returned non-zero exit status 1

It looks to me like the failure point is /usr/bin/python: No module named pip

PS I am using the 'Using Ubuntu' steps and the previous apt install step gives me

XXX:~/git/esp-idf$ sudo apt install git wget flex bison gperf python3 python3-pip python3-setuptools python3-serial python3-click python3-cryptography python3-future python3-pyparsing python3-pyelftools cmake ninja-build ccache libffi-dev libssl-dev libusb-1.0-0
[sudo] password for XXX: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
bison is already the newest version (2:3.5.1+dfsg-1).
ccache is already the newest version (3.7.7-1).
cmake is already the newest version (3.16.3-1ubuntu1).
flex is already the newest version (2.6.4-6.2).
git is already the newest version (1:2.25.1-1ubuntu3).
libffi-dev is already the newest version (3.3-4).
libssl-dev is already the newest version (1.1.1f-1ubuntu2).
libusb-1.0-0 is already the newest version (2:1.0.23-2build1).
python3 is already the newest version (3.8.2-0ubuntu2).
python3-click is already the newest version (7.0-3).
python3-cryptography is already the newest version (2.8-3).
python3-future is already the newest version (0.18.2-2).
python3-pyelftools is already the newest version (0.26-1ubuntu1).
python3-pyparsing is already the newest version (2.4.6-1).
python3-serial is already the newest version (3.4-5.1).
python3-setuptools is already the newest version (45.2.0-1).
wget is already the newest version (1.20.3-1ubuntu1).
gperf is already the newest version (3.1-1build1).
ninja-build is already the newest version (1.10.0-1build1).
python3-pip is already the newest version (20.0.2-5ubuntu1).
The following package was automatically installed and is no longer required:
  libfprint-2-tod1
Use 'sudo apt autoremove' to remove it.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.