This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot:examples:quickstart [2023/03/01 21:52] – raivo.sell | en:iot:examples:quickstart [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 44: | Line 44: | ||
{{: | {{: | ||
- | After that, the PlatformIO icon should | + | After that, the PlatformIO icon should |
{{: | {{: | ||
+ | |||
+ | ====== Creating your first project ====== | ||
+ | |||
+ | =====Using PlatformIO IDE===== | ||
+ | |||
+ | On VS Code, click on the PlartfomIO **Home** icon. Click on **+ New Project** to start a new project. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Give your project a name, select the board **WeMos D1 MINI ESP32 (WEMOS)** and the framework as **Arduino Framework** | ||
+ | |||
+ | {{: | ||
+ | |||
+ | After finishing the setup the project should be accessible from the explorer tab. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ====platformio.ini file==== | ||
+ | |||
+ | The **platformio.ini** file is the PlatformIO Configuration File for your project. It shows the platform, board, and framework for your project. You can also add other configurations like libraries to be included, upload options, changing the Serial Monitor baud rate and other configurations. | ||
+ | |||
+ | Add the following line to include the ITTIoT Library and other parameters (check correct port instead of example COM3): | ||
+ | |||
+ | < | ||
+ | upload_speed = 921600 | ||
+ | upload_port = COM3 | ||
+ | // | ||
+ | monitor_speed = 115200 | ||
+ | lib_deps = ITTIoT | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ====src folder==== | ||
+ | |||
+ | The **src** folder is your working folder. Under the src folder, there’s a main.cpp file. That’s where you write your code. Click on that file. The structure of an Arduino program should open with the setup() and loop() functions. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Paste the following example code to main.cpp | ||
+ | |||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | void iot_received(String topic, String msg){ | ||
+ | Serial.print(" | ||
+ | Serial.print(topic); | ||
+ | Serial.print(" | ||
+ | Serial.println(msg); | ||
+ | } | ||
+ | |||
+ | void iot_connected(){ | ||
+ | Serial.println(" | ||
+ | iot.subscribe(" | ||
+ | iot.log(" | ||
+ | } | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | iot.setConfig(" | ||
+ | iot.setConfig(" | ||
+ | iot.setConfig(" | ||
+ | iot.setConfig(" | ||
+ | iot.setConfig(" | ||
+ | iot.setConfig(" | ||
+ | iot.printConfig(); | ||
+ | iot.setBootPin(5); | ||
+ | iot.setup(); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | iot.handle(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Make sure to replace the connection information with yours. | ||
+ | |||
+ | =====Uploading code using PlatformIO IDE===== | ||
+ | |||
+ | To test and upload your code, first save your code and then click on the **Build** icon at the bottom of the editor to verify that your code can be run. After a successful build, press the **Upload** icon. Alternatively, | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ====== Verifying the connection ====== | ||
+ | |||
+ | |||
+ | If the code is compiled and uploaded successfully, | ||
+ | |||
+ | {{: | ||
+ | |||
+ | If the serial monitor does not open automatically, | ||
+ | |||
+ | {{: | ||
+ | |||
+ | This means the code was successfully uploaded, and the board was connected to the MQTT server. | ||
+ | |||
+ | Install the [[https:// | ||
+ | |||
+ | Configure the connection with your details and publish a message to the topic that your board is listening to (// | ||
+ | |||
+ | The board should receive the message and print it out on the serial monitor: | ||
+ | |||
+ | {{: | ||
+ |