Skip to content

Commit 43cf758

Browse files
committed
initial draft of migration
1 parent 2d67e59 commit 43cf758

File tree

8 files changed

+102
-2
lines changed

8 files changed

+102
-2
lines changed

docs/vscode/images/build.png

135 KB
Loading

docs/vscode/images/component.png

81.6 KB
Loading

docs/vscode/images/diagram.png

57.9 KB
Loading
File renamed without changes.

docs/vscode/images/pio-library.png

90.7 KB
Loading

docs/vscode/migrating.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,106 @@
11
---
22
title: Migrating Wokwi projects to VS Code
3-
sidebar_label: Migrating
3+
sidebar_label: Migrating to VS Code
44
description: Migrate your online Wokwi simulator projects to a local VS Code environment
55
keywords: [Visual Studio Code, VS Code, embedded simulation, IoT simulation, PlatformIO, ESP-IDF, Arduino, MicroPython, Rust, Zephyr]
66
---
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
10+
The web-based Wokwi simulator is a powerful and well-integrated way to try out your project designs: there are many capabilities which "just work" in the online simulator which will require some additional steps or workarounds to build and run locally.
11+
12+
This checklist of steps should help you overcome the most common issues. It is assumed that you have already installed the VS Code extension for Wokwi (see the [Getting started guide](./getting-started)).
13+
14+
## Download the project source
15+
16+
To start, the first step is to save your online project. From the same menu, under the save button, you can then select to download a `.zip` archive of the project. This will contain useful files such as any source code and the `diagram.json` file used by Wokwi.
17+
Once downloaded you can extract the files from the archive and use them in your local project.
18+
19+
## Create an empty project in VS Code
20+
21+
If you are using an extension such as ESP-IDF or PlatformIO in VS Code, it is far easier to create an empty template project first before adding your Wokwi code. Use the provided templates for your chosen platform to create a new empty project. This will include specifying the hardware to be targeted and will create the required source structure and build files.
22+
23+
This step will create a boilerplate project in a working state, ready to add your own code.
24+
25+
## Add the source
26+
27+
Depending on the complexity of your project, adding the source should be quite straightforward. For a new PlatformIO Arduino project, the directory tree should look like this:
28+
29+
```text
30+
├── .gitignore
31+
├── include
32+
│ └── README
33+
├── lib
34+
│ └── README
35+
├── .pio
36+
│ └── build
37+
│ ├── project.checksum
38+
│ └── uno
39+
│ └── idedata.json
40+
├── platformio.ini
41+
├── src
42+
│ └── main.cpp
43+
├── test
44+
│ └── README
45+
46+
```
47+
48+
In this case you would replace the contents of `/src/main.cpp` with the contents of the '.ino' file from the project you downloaded (it's often easier to delete the `main.cpp` file, copy in your `.ino` file and then rename it to `main.cpp`).
49+
50+
51+
## Verify/add libraries
52+
53+
If your project has used any additional libraries you may need to resolve them for your local build environment. The Wokwi online simulator includes access to a whole range of built-in and third party libraries which you may have added to your project - now your local build environment will also need them. It is usually better to use the library manager included with your build tools to ensure that you get an up to date and known working version of the library.
54+
55+
<Tabs>
56+
<TabItem value="pio" label="PlatformIO" default>
57+
If you are using PlatformIO in VS Code, many libraries are available in the Library Manager. Use the `libraries.txt` file downloaded with your project as a guide to the names of the libraries you need.
58+
59+
The PlatformIO Library Manager has a search facility which will make this easier - just copy in the name of the library and hit search. Clicking on the 'Add' button will add the library to the `platformio.ini` file for each of the build targets you have configured.
60+
61+
![PlatformIO Library Manager](./images/pio-library.png)
62+
63+
Note that many libraries have similar or sometimes even the same name.
64+
65+
</TabItem>
66+
<TabItem value="ESP-IDF" label="ESP-IDF">
67+
If you are using the ESP-IDF extension for VS Code, libraries are managed as 'components'. A component is any modular code object compiled as a static library. The component library for ESP-IDF, much like the Library Manager in PlatformIO, contains many useful libraries maintained by Espressif, and tested third-party contributions.
68+
69+
![ESP-IDF Component Manager](./images/component.png)
70+
71+
</TabItem>
72+
<TabItem value="Manual" label="Custom libraries">
73+
If the library you wish to use isn't available in the supported available libraries, you can add it manually.
74+
75+
For PlatformIO, the [library documentation](https://docs.platformio.org/en/latest/librarymanager/creating.html) will give further guidance.
76+
77+
For ESP-IDF projects, custom libraries can be added as a component. Check out the [ESP-IDF project structure documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#example-project) for more details.
78+
</TabItem>
79+
</Tabs>
80+
81+
## Test the build tools
82+
83+
The Wokwi simulator requires a built firmware file to run, so the next step should be to check that you can generate one. Use the relevant build command from your chosen framework to build the files.
84+
85+
Check the terminal window output for any errors or warnings which you may want or need to correct.
86+
87+
![PlatformIO build success](images/build.png)
88+
89+
## Add configuration
90+
91+
The online simulator controls its own build environment. To work locally in VS Code, you will need to provide an extra configuration file, `wokwi.toml`. This will not be part of the downloaded archive because Wokwi doesn't know what build tools or framework you will use for local VS Code development.
92+
93+
The structure and contents of the `wokwi.toml` file are covered in the [VS Code project configuration page](/vscode/project-config). In the previous step you already built the firmware files needed.
94+
95+
At this point you should also add the `diagram.json` file from your downloaded project. This must be in the same directory as the `wokwi.toml` file.
96+
97+
## Test the simulator
98+
99+
When you select the `diagram.json` file in the VS Code editor, it will automatically open an embedded window with a graphical display showing the Wokwi circuit layout.
100+
101+
![Wokwi diagram](./images/diagram.png)
102+
103+
Use the start button in this window to start the simulation. The simulation should run exactly as it did in the online Wokwi simulator.
104+
105+
Note: You will need a license to edit the diagram in this view ([see the Wokwi pricing page](https://wokwi.com/pricing?ref=docs_migrating)).
7106

docs/vscode/offline-mode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Wokwi for VS Code requires an internet connection to run. If you need to use Wok
99

1010
When running in offline mode, the title of the simulator tab will be "Wokwi Simulator (Offline)", and the simulator will display the date when the simulation engine was last updated:
1111

12-
![Wokwi Simulator (Offline)](./offline-mode.png)
12+
![Wokwi Simulator (Offline)](./images/offline-mode.png)
1313

1414
To update the simulator engine, go online and start the simulator. The simulator will automatically update the engine to the latest version, and will use it the next time you run the simulator in offline mode.
1515

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module.exports = {
9292
'vscode/diagram-editor',
9393
'vscode/debugging',
9494
'vscode/offline-mode',
95+
'vscode/migrating',
9596
],
9697
'Wokwi CI': [
9798
'wokwi-ci/getting-started',

0 commit comments

Comments
 (0)