Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot:examples:quickstart [2022/05/10 08:50] raivo.sellen:iot:examples:quickstart [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
 ====== Quickstart guide ====== ====== Quickstart guide ======
  
-  - [[en:iot:examples:quickstart:qs1]] +====== Configuring the development environment ====== 
-  - [[en:iot:examples:quickstart:qs2]] + 
-  [[en:iot:examples:quickstart:qs3]]+Download and install VS Code from [[https://code.visualstudio.com/|here]] 
 + 
 +=====Install Python on Windows===== 
 + 
 +Download Python from [[https://www.python.org/downloads/|here]] 
 + 
 +Before installing check the **Add Python to PATH** 
 + 
 +{{:en:iot:examples:setup:check.png?200|}} 
 + 
 +=====Install Python on Linux===== 
 + 
 +Open terminal and check if you have Python 3 installed. 
 + 
 +<code> 
 +$ python3 --version 
 +</code> 
 + 
 +If you don't have Python 3 installed then run the following command. 
 +<code> 
 +$ sudo apt install python3 
 +</code> 
 + 
 +Wether you already had Python installed or not, you need to run the following command. 
 +<code> 
 +$ sudo apt install python3-distutils 
 +</code> 
 + 
 +=====Installing PlatformIO IDE on VS Code===== 
 + 
 +  - Click on the **Extensions** icon or press **Ctrl+Shift+X** to open the extensions tab 
 +  - Search for "PlatformIO IDE" 
 +  - Select the first option 
 +  - Click the **Install** button 
 + 
 +{{:en:iot:examples:setup:installplatformio.png?600|}} 
 + 
 +After installing make sure the extension is enabled. 
 + 
 +{{:en:iot:examples:setup:enabled.png?600|}} 
 + 
 +After that, the PlatformIO icon should appear on the left sidebar and a **Home** icon redirects you to PlatformIO home. If not, restart Visual Studio Code. 
 + 
 +{{:en:iot:examples:setup:home.png?600|}} 
 + 
 +====== 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. 
 + 
 +{{:en:iot:examples:setup:new-project.png?600|}} 
 + 
 +Give your project a name, select the board **WeMos D1 MINI ESP32 (WEMOS)** and the framework as **Arduino Framework** 
 + 
 +{{:en:iot:examples:quickstart:doc1.png?600|}} 
 + 
 +After finishing the setup the project should be accessible from the explorer tab. 
 + 
 +{{:en:iot:examples:setup:explorer.png?600|}} 
 + 
 +====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): 
 + 
 +<code> 
 +upload_speed = 921600 
 +upload_port = COM3 
 +//upload_port = COM3 // In case of Linux /dev/ttyUSB0 
 +monitor_speed = 115200 
 +lib_deps = ITTIoT 
 +</code> 
 + 
 +{{:en:iot:examples:quickstart:platformio_ini.png?600|}} 
 + 
 +====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. 
 + 
 +{{:en:iot:examples:setup:src.png?600|}} 
 + 
 +Paste the following example code to main.cpp 
 + 
 +<code c> 
 +#include <Arduino.h> 
 +#include <ittiot.h> 
 + 
 +void iot_received(String topic, String msg){ 
 +    Serial.print("MSG FROM USER callback, topic: "); 
 +    Serial.print(topic); 
 +    Serial.print(" payload: "); 
 +    Serial.println(msg); 
 +
 + 
 +void iot_connected(){ 
 +    Serial.println("MQTT connected callback"); 
 +    iot.subscribe("mytopic"); 
 +    iot.log("Hello from ESP!"); 
 +
 + 
 +void setup() { 
 +    Serial.begin(115200); 
 +    iot.setConfig("wname", "myWiFi"); //Your wifi name 
 +    iot.setConfig("wpass", "myPassword"); // Your wifi password 
 +    iot.setConfig("msrv", ""); // Your MQTT broker IP 
 +    iot.setConfig("mport", ""); // Your MQTT broker port default: 1883 
 +    iot.setConfig("muser", ""); // Your MQTT broker user name - default empty 
 +    iot.setConfig("mpass", ""); // Your MQTT broker password - default empty 
 +    iot.printConfig(); // print json config to serial 
 +    iot.setBootPin(5); 
 +    iot.setup(); 
 +
 + 
 +void loop() { 
 +    iot.handle(); 
 +
 +</code> 
 + 
 +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, you can go to the **PIO Project Tasks** menu and select build or upload from there. 
 + 
 +{{:en:iot:examples:setup:buildupload.png?600|}} 
 + 
 + 
 +====== Verifying the connection ====== 
 + 
 + 
 +If the code is compiled and uploaded successfully, a serial monitor should have automatically opened, and you should see live data from the controller like: 
 + 
 +{{:en:iot:examples:quickstart:doc3-1.png?600|}} 
 + 
 +If the serial monitor does not open automatically, click the button below: 
 + 
 +{{:en:iot:examples:quickstart:doc3-2.png?600|}} 
 + 
 +This means the code was successfully uploaded, and the board was connected to the MQTT server. 
 + 
 +Install the [[https://chrome.google.com/webstore/detail/mqttbox/kaajoficamnjijhkeomgfljpicifbkaf|MQTTBox]] chrome app to publish and subscribe messages to the MQTT server. 
 + 
 +Configure the connection with your details and publish a message to the topic that your board is listening to (//mytopic// in the example) 
 + 
 +The board should receive the message and print it out on the serial monitor: 
 + 
 +{{:en:iot:examples:quickstart:doc4-1.png?600|}} 
en/iot/examples/quickstart.1652172653.txt.gz · Last modified: 2022/05/10 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0