Code Monkey home page Code Monkey logo

wokwigw's Introduction

Wokwi IoT Network Gateway

Connect your Wokwi simulated IoT Devices (e.g. ESP32) to you local network!

For installation and usage instructions, check out the Wokwi ESP32 WiFi Guide

Usage

Run wokwigw and configure Wokwi to use the Private IoT Server:

  • In wokwi.com - Press "F1" in the code editor and select "Enable Private Wokwi IoT Gateway".
  • In Wokwi for VS Code - Add the following line to your wokwi.toml file:
[net]
gateway="ws://localhost:9011"

Port forwarding

The wokwigw tool can forward ports from your local machine to the simulated device. For example, if you have a web server running on port 80 on your simulated device, you can forward port 8080 on your local machine to port 80 on the simulated device:

wokwigw --forward 8080:10.13.37.2:80

To forward a UDP port, add the udp: prefix. For instance, the following command will forward UDP port 8888 on your local machine to UDP port 1234 on the simulated device:

wokwigw --forward udp:8888:10.13.37.2:1234

You can repeat the --forward flag multiple times to forward multiple ports.

Connecting from the simulation to your local machine

To connect from the simulation to your local machine (that is the machine running wokwigw), use the host host.wokwi.internal. For example, if you are running an HTTP server on port 1234 on your computer, you can connect to it from within the simulator using the URL http://host.wokwi.internal:1234/.

Building

make

The compiled binaries go into the bin directory, as follows:

  • wokwigw.exe - Windows, x86_64
  • wokwigw-darwin - Mac OS X, x86_64
  • wokwigw-darwin_arm64 - Mac OS X, arm64
  • wokwigw-linux - Linux, x86_64
  • wokwigw-linux_arm64 - Linux, arm64

Testing

make test

Cloud build environment (Gitpod)

Gitpod allows you to edit the code, build the project in the cloud, and then download the compiled binary. Here are the instructions:

  1. Open this project in Gitpod. You may need to authenticate using your GitHub account.
  2. You'll get an online code editor where you can make changes to the source code. Make your code changes.
  3. Go to Gitpod's built-in terminal and type make to compile the project (you can also type make test to run the tests).

You can download the compiled binaries from the bin directory by locating them in the file explorer, right-clicking the binary you want to download, and selecting "Download...".

wokwigw's People

Contributors

bonnyr avatar urish avatar

Stargazers

 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

wokwigw's Issues

Accessing resources running on local machine from ESP32

Hi,

I have an HTTP sever running on my local machine, on port 5000, that I would like to access from an ESP32 simulator. I just purchased the Wokwi Club subscription, have the private gateway running on my local machine, and have successfully run the "ESP32 HTTP Server" example project.

My question is how do I go about accessing an HTTP server running on my local machine from a simulated ESP32? Effectively the opposite of the "ESP32 HTTP Server" example project.

I assume this is what the line "Your ESP32 projects can access services running on your computer or your local network (e.g. a local MQTT or HTTP server)" on the ESP32 WiFi Networking page means, right?

Thank you for your help

webserver esp32

/* ESP32 HTTP IoT Server Example for Wokwi.com

https://wokwi.com/arduino/projects/320964045035274834

To test, you need the Wokwi IoT Gateway, as explained here:

https://docs.wokwi.com/guides/esp32-wifi#the-private-gateway

Then start the simulation, and open http://localhost:9080
in another browser tab.

Note that the IoT Gateway requires a Wokwi Club subscription.
To purchase a Wokwi Club subscription, go to https://wokwi.com/club
*/

#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <uri/UriBraces.h>

#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
// Defining the WiFi channel speeds up the connection:
#define WIFI_CHANNEL 6

WebServer server(80);

const int LED1 = 26;
const int LED2 = 27;

bool led1State = false;
bool led2State = false;

void sendHtml() {
String response = R"(


<title>ESP32 Web Server Demo</title>

<style>
html { font-family: sans-serif; text-align: center; }
body { display: inline-flex; flex-direction: column; }
h1 { margin-bottom: 1.2em; }
h2 { margin: 0; }
div { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; grid-auto-flow: column; grid-gap: 1em; }
.btn { background-color: #5B5; border: none; color: #fff; padding: 0.5em 1em;
font-size: 2em; text-decoration: none }
.btn.OFF { background-color: #333; }
</style>

  <body>
    <h1>ESP32 Web Server</h1>

    <div>
      <h2>LED 1</h2>
      <a href="/toggle/1" class="btn LED1_TEXT">LED1_TEXT</a>
      <h2>LED 2</h2>
      <a href="/toggle/2" class="btn LED2_TEXT">LED2_TEXT</a>
    </div>
  </body>
</html>

)";
response.replace("LED1_TEXT", led1State ? "ON" : "OFF");
response.replace("LED2_TEXT", led2State ? "ON" : "OFF");
server.send(200, "text/html", response);
}

void setup(void) {
Serial.begin(115200);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
Serial.print("Connecting to WiFi ");
Serial.print(WIFI_SSID);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");

Serial.print("IP address: ");
Serial.println(WiFi.localIP());

server.on("/", sendHtml);

server.on(UriBraces("/toggle/{}"), {
String led = server.pathArg(0);
Serial.print("Toggle LED #");
Serial.println(led);

switch (led.toInt()) {
  case 1:
    led1State = !led1State;
    digitalWrite(LED1, led1State);
    break;
  case 2:
    led2State = !led2State;
    digitalWrite(LED2, led2State);
    break;
}

sendHtml();

});

server.begin();
Serial.println("HTTP server started");
}

void loop(void) {
server.handleClient();
delay(2);
}

Add UDP port forwarding support

Hello there. I'm using the CNMAT OSC library Open Sound Control.
It works perfectly sending OSC messages to localhost, using the private Gateway, but I haven't been capable of receiving OSC messages in UDP format into the simulator.

I'm afraid that the Wokwi IoT Gateway is just listening for TCP connections, and OSC uses UDP.

I'd like to be able to receive OSC messages in a UDP format.

Best regards, thanks you.

Context Deadline exceeded error

Installed on MacOS and Windows 10 and get same error and failed connection to localhost:9080

using this project: https://wokwi.com/projects/320964045035274834

output:
Wokwi IoT Gateway

Version: v0.1.2
Git revision: 664f0cf
Built: Mon, 31 Jan 2022 20:05:22 +0000

Listening on TCP port 9011
Client connected: 127.0.0.1:58437
time="2022-03-30T23:26:08-05:00" level=info msg="new connection from 127.0.0.1:58438 to 127.0.0.1:58439"
2022/03/30 23:27:14 tcpproxy: for incoming conn [::1]:58472, error dialing "10.13.37.2:80": context deadline exceeded
2022/03/30 23:27:14 tcpproxy: for incoming conn [::1]:58473, error dialing "10.13.37.2:80": context deadline exceeded
2022/03/30 23:27:17 tcpproxy: for incoming conn [::1]:58479, error dialing "10.13.37.2:80": connect tcp 10.13.37.2:80: no route
2022/03/30 23:27:28 tcpproxy: for incoming conn [::1]:58480, error dialing "10.13.37.2:80": context deadline exceeded
2022/03/30 23:27:28 tcpproxy: for incoming conn [::1]:58481, error dialing "10.13.37.2:80": context deadline exceeded
2022/03/30 23:27:35 tcpproxy: for incoming conn [::1]:58483, error dialing "10.13.37.2:80": connect tcp 10.13.37.2:80: no route
2022/03/30 23:32:53 tcpproxy: for incoming conn [::1]:64094, error dialing "10.13.37.2:80": connect tcp 10.13.37.2:80: no route
2022/03/30 23:32:53 tcpproxy: for incoming conn [::1]:64095, error dialing "10.13.37.2:80": connect tcp 10.13.37.2:80: no route
2022/03/30 23:32:56 tcpproxy: for incoming conn [::1]:64097, error dialing "10.13.37.2:80": connect tcp 10.13.37.2:80: no route

AWS IoT Core not connecting to server.

Hi I have an issue connecting to MQTT server on AWS. The code is working correctly on actual harware but it is not working on wowkwi. I tried using the private gateway too but it is not working. Is it issue on aws side or is it supported by wokwi?

`GLIBC_2.3x' not found while installing Wokwi IoT Gateway on Chromebook

./wokwigw-linux: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.32' not found (required by ./wokwigw-linux) ./wokwigw-linux: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.34' not found (required by ./wokwigw-linux)

I was shy to attempt (with vague information) to fix this being warned that GLIBC is deeply rooted.

Operating System

cat /etc/os-release
lsb_release -a
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Kernel Information

uname -a
Linux penguin 5.15.108-18910-gab0e1cb584e1 #1 SMP PREEMPT Sat Jun 3 18:21:02 PDT 2023 x86_64 GNU/Linux

System Architecture

uname -m
x86_64

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.