networking and communications (week14)

Group Assignment

individual assignment:
write an application that interfaces a user with an input &/or output device that you made
group assignment:
compare as many tool options as possible

Link to Fab Academy 2020 assessment page


MQTT

Network - host MQTT configuration

I hosted MQTT broker on AWS IoT and configured things, certification and security, policy.

The purpose of this is benchmarking MQTT for validating configuration, coding and performance. If it's useful, this is one of candidate networking infrastructures to make a "distributed musical device" idea, that Japan Fabacademy 2020 students work together for make musical device for each home location and play it together in remote place. This project is for group assignment of mechanical design and machine design week.

I described about general configuration in my individual page. Please look thorough:


MQTT client implementation on ESP32

Environment and libraries

Environment (as an example)
Board: ESP32 DevkitC
IDE: Arduino IDE (1.8.10) on Mac OS Mojave (10.14.6)
Board manager on Arduino IDE: ESP32 Wrover Module
Wifi: 2.4GHz (802.11ac)

Library for Arduino code
ArduinoJson by Benoit Blanchon (ver 6.9.1)
PubSubClient by Nick O'Leary (ver 2.7.0)

Client implementation procedure

Environmental setup
  1. Download client source code template
  2. Setup board manager
  3. On Arduino IDE, Tool > Board > ESP Wrover Module

    Check other parameters like "partition scheme" as "Default 4MB with spiffs"

  4. Install required libraries on Arduino IDE
  5. On Arduino IDE, Tool > Manage Library , Install following libraries. Make sure following version especially in major version more than ArduinoJson ver.6 and PubSubClient ver.2)

    • ArduinoJson by Benoit Blanchon (ver 6.9.1)
    • PubSubClient by Nick O'Leary (ver 2.7.0)

    If you cannot find "Manage libraries" in "Tool" tab on Arduino IDE, check "Sketch" > "Include Library" "Manage Libraries".

  6. Configure max packet size configuration in PubSubClient.h
  7. At PubSubClient.h in library, Change #define MQTT_MAX_PACKET_SIZE 128 to #define MQTT_MAX_PACKET_SIZE 512

    PubSubClient.h will be the location like in ~/[Arduino home]/libraries/PubsubClient/src in your local computer.

Coding
  1. Set your WiFi SSID and password
  2. // 1)----- set your ssid and password -----
      char *ssid = "xxxxxxxxxx";
      char *password = "xxxxxxxxxx";
  3. Configure your topic (or for your use to publish/receive message)
  4. // 2)----- configure your topic (or for your use to connect to other people) ----- 
      // Topic name needs to be format in "fa2020jp/topic[*]"
      // Topic for publishing (if you do not need to publish, you do not need pubTopic. 
      char *pubTopic1 = "fa2020jp/topic1";
      char *pubTopic2 = "fa2020jp/topic2";

    Following is topic name rule for FabAcademy 2020 MTM Japan group project. Following is just a rule for asigninig topic. In program, topics are generated dynamically under policy of "fa2020jp/topic[*]".

    person topic name memo
    Common fa2020jp/topic0 common topic for everyone. You may publish here for dispatch message used for everyone
    Homma fa2020jp/topic1
    Kimura fa2020jp/topic2
    Tsuchiyama fa2020jp/topic3
    Oka fa2020jp/topic4
    HARU(Oguri) fa2020jp/topic5
    Yanome fa2020jp/topic6
    Yume fa2020jp/topic7
    Tamiya fa2020jp/topic8
  5. Specify your topic name to subscribe in connectAWSIoT()
  6. // 3) ----- Specify your topic name to subscribe ----- 
      mqttClient.subscribe([topic name], qos);
  7. Write your logic on receiving message in mqttCallback()
  8. // 4) ----- Write your logic on received message -----
      void mqttCallback (char* topic, byte* payload, unsigned int length) {
      // 
      }
  9. Write your logic for publishing message in mqttLoop()
  10. void mqttLoop() {
      if (!mqttClient.connected()) {
          connectAWSIoT();
      }
      mqttClient.loop();
    
      // 5) ----- Write your logic for publishing message from here ----- 
      // (If you are not publishing anything, you can delete following code)

Rules for implementing MQTT client (to "FA2020JpDevice1" in MQTT broker)

  • For publishing, please consider your test code not running in unnecessarily frequency. AWS IoT is cheap but costs slightly (like 0.096US/1M connections, 1.20USD/1B messages)
  • Please disconnect your client after you finish to use it by the same reason with above
  • Check your topic name and use it
  • Do NOT reveal certification information and source code embedded that information in any sharable place

Experiment result in multiple site

We did experiment for validate how multiple clients of MQTT work in remote location with hiroaki.kimura & hideo.oguri)

The result is in individual assignment page