|
| 1 | +# Arduino Flask Wifi Server |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-<arduino-wifi-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +This sample contains an interactive wifi-connected UI program for a [SenseCAP Indicator Device](https://wiki.seeedstudio.com/Sensor/SenseCAP/SenseCAP_Indicator/Get_started_with_SenseCAP_Indicator/), built for an Embedded Systems project at Defang Software Labs. |
| 8 | + |
| 9 | +The device has a square liquid-crystal touch screen display, and a ESP32-S3 chip that can be programmed in an Arduino environment. |
| 10 | + |
| 11 | +The program `welcome.ino`, acting as a client, pings data every 5 seconds after it is connected to a wifi network. It uses a library called [ArduinoHTTPClient](https://github.com/arduino-libraries/ArduinoHttpClient). It is also recommended to use [Arduino IDE](https://www.arduino.cc/en/software) when coding with `.ino` files. The program UI will display a message that is randomized in color and location on the screen at the same time during pings (every 5 seconds). |
| 12 | + |
| 13 | +The Flask server in `web_server.py` receives these pings when it is initialized and connected to the same wifi network as the client. To initalize it, run `python web_server.py`. To view it, open `localhost` with the port number used. To deploy it to the cloud, run `defang up` in the `\welcome` directory. |
| 14 | + |
| 15 | +A helpful file called `serial_reader.py` decodes serial monitor readings to a readable format, allowing you to see `Serial.println()` messages in real time when running. To initalize it, run `python serial_reader.py` and see it show up in the terminal. |
| 16 | + |
| 17 | +Here is a diagram showing the structure of the application. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 24 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 25 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 26 | + |
| 27 | +## Development |
| 28 | + |
| 29 | +To run the application locally, you can use the following command: |
| 30 | + |
| 31 | +```bash |
| 32 | +docker compose up --build |
| 33 | +``` |
| 34 | + |
| 35 | +## Configuration |
| 36 | + |
| 37 | +For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration). |
| 38 | + |
| 39 | +If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`. |
| 40 | + |
| 41 | +```bash |
| 42 | +defang config set API_KEY |
| 43 | +``` |
| 44 | + |
| 45 | +## Deployment |
| 46 | + |
| 47 | +> [!NOTE] |
| 48 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 49 | +
|
| 50 | +### Defang Playground |
| 51 | + |
| 52 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 53 | +```bash |
| 54 | +defang compose up |
| 55 | +``` |
| 56 | + |
| 57 | +### BYOC |
| 58 | + |
| 59 | +If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud). |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +Title: Arduino Flask Wifi Server |
| 64 | + |
| 65 | +Short Description: An Arduino wifi server built with Flask. |
| 66 | + |
| 67 | +Tags: Arduino, Flask, Python, IoT, Wifi, Serial |
| 68 | + |
| 69 | +Languages: python |
0 commit comments