This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:u8 [2019/08/10 20:55] – pczekalski | en:iot-open:remotelab:sut:generalpurpose2:u8 [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 17: | Line 17: | ||
| === Scenario === | === Scenario === | ||
| - | I this scenario, once you get connected to the WiFi as AP and then to the MQTT server to publish data, you will periodically read A0 (analogue) input of the ESP8266 and publish its raw value to the MQTT server. | + | I this scenario, once you get connected to the WiFi as AP and then to the MQTT server to publish data, you will periodically read A0 (analogue) input of the ESP8266 and publish its RAW value to the MQTT server. You will also visualise the RAW value of the A0 input reading on the LCD screen. |
| === Result === | === Result === | ||
| - | You should be able to read data stream via MQTT message, presenting flap position. Note - flap position refers to the airflow: you may need to control it using VREL2 and VREL4 for VREL1 and VREL3, respectively. Airflow in nodes 2 and 4 can be controlled twofold: using PWM to control fan rotation speed and using the flap to open/close air duct. | + | You should be able to read data stream via MQTT message, presenting flap position. |
| === Start === | === Start === | ||
| Line 28: | Line 28: | ||
| Following steps do not present full code - you need to supply missing parts on your own! We do not present here how to connect to the WiFi AP. If you're in doubt, rever to the U1 scenario. Please refer to scenario B1, if you need a recall on how to handle LCD screen. In case you're in doubt how to handle MQTT messages communication (here publishing/ | Following steps do not present full code - you need to supply missing parts on your own! We do not present here how to connect to the WiFi AP. If you're in doubt, rever to the U1 scenario. Please refer to scenario B1, if you need a recall on how to handle LCD screen. In case you're in doubt how to handle MQTT messages communication (here publishing/ | ||
| == Step 1 == | == Step 1 == | ||
| - | //Describe activities done in Step 1.// | + | Include all necessary libraries. We use PubSubClient library to contact MQTT broker. The minimum set here is: |
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| ... | ... | ||
| + | </ | ||
| + | There is no need to use a special library to read analogue input representing relative flap position here.\\ | ||
| + | Declare some identifiers to let you easier handle necessary modifications and keep code clear: | ||
| + | <code c> | ||
| + | #define wifi_ssid " | ||
| + | #define wifi_password " | ||
| + | #define mqtt_server " | ||
| + | #define mqtt_user " | ||
| + | #define mqtt_password " | ||
| + | ... | ||
| + | </ | ||
| + | == Step 2 == | ||
| + | Declare some identifiers, | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | <code c> | ||
| + | // MQTT messages | ||
| + | #define MQTTClientName ...<your client name> | ||
| + | #define analogOutTopic | ||
| + | // i.e. including your name | ||
| + | |||
| + | //MQTT last will | ||
| + | #define lastWillTopic ...<some topic for exposing state and last will> | ||
| + | // give it some unique topic | ||
| + | // i.e. including your name | ||
| + | #define lastWillMessage " | ||
| + | #define mqttWelcomeMessage " | ||
| + | </ | ||
| + | |||
| + | == Step 3 == | ||
| + | Declare WiFiCilent, PubSubClient, | ||
| + | |||
| + | == Step 4 == | ||
| + | Prepare MQTT publishing code, here we publish periodically one value (flap position, relative), i.e. like this: | ||
| + | <code c> | ||
| + | void mqttPublish() | ||
| + | { | ||
| + | flap = analogRead(A0); | ||
| + | | ||
| + | if(client.connected()) | ||
| + | { | ||
| + | client.publish(analogOutTopic, | ||
| + | // messages | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | <note important> | ||
| - | == Step n == | + | == Step 5 == |
| - | //Describe activities done in Step n.// | + | Your '' |
| + | <code c> | ||
| + | void loop() | ||
| + | { | ||
| + | if (!client.connected()) { | ||
| + | reconnect(); | ||
| + | } | ||
| + | client.loop(); | ||
| + | mqttPublish(); | ||
| + | sprintf(buffer," | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(buffer); | ||
| + | delay(1000); | ||
| + | } | ||
| + | </code> | ||
| + | <note warning> | ||
| + | <note tip>The '' | ||
| === Result validation === | === Result validation === | ||
| - | Observe, | + | Observe |
| === FAQ === | === FAQ === | ||
| - | This section is to be extended as new questions appear. \\ | + | **I want to implement PID controller |
| - | When using the printed version | + | |
| - | //Provide some FAQs in the following form:\\ | + | |
| - | **Question?**: Answer. | + | |
| - | // | + | |