SANJIVANI FAB LAB

Week 11: Networking and Communications

Wired Communication Protocols Overview

RS-485 (Modbus RTU)

RS-485 is a widely used protocol known for its noise-resistant differential signaling, supporting both half and full-duplex communication. With speeds of up to 10 Mbps and an extensive range of 1200 meters, RS-485 enables multi-drop connections, making it ideal for industrial PLC communication and sensor networks. The Modbus RTU protocol further enhances its functionality by facilitating master-slave communication over RS-485.

I2C (Inter-Integrated Circuit)

I2C is a synchronous multi-master, multi-slave communication protocol designed for short-distance PCB-level connections. Operating at speeds ranging from 100 kHz to 5 MHz, it utilizes two lines: SCL (clock) and SDA (data), requiring pull-up resistors. Its 7-bit or 10-bit addressing scheme enables efficient device communication, making it a popular choice for sensors, EEPROMs, and peripheral integration.

SPI (Serial Peripheral Interface)

For high-speed data transmission, SPI excels with speeds of up to 100+ Mbps over short distances. This synchronous, full-duplex protocol operates on four primary lines: SCLK (clock), MOSI (Master Out Slave In), MISO (Master In Slave Out), and SS/CS (Slave Select). SPI is widely employed in flash memory, display modules, and other high-speed peripheral applications due to its low-latency and fast data transfer rates.

CAN Bus (Controller Area Network)

CAN Bus is a multi-master, differential signaling protocol designed for noise resistance and real-time communication. Supporting speeds up to 1 Mbps, with CAN FD extending its capabilities, it is optimal for linear bus topologies requiring termination resistors. With a range reaching 500 meters at lower speeds, CAN Bus is extensively used in automotive and industrial control systems, ensuring efficient communication between multiple nodes in dynamic environments.

Comparison Table

Comparison Table

Protocol Speed Topology Distance Use Case
RS-485 ≤10 Mbps Multi-drop 1200m Industrial Modbus
I2C ≤5 MHz Shared bus Short PCB-level sensors
SPI ≤100+ Mbps Point-to-point Short High-speed peripherals
CAN Bus ≤1 Mbps Linear bus 500m Automotive/Industrial

Wireless IoT Communication Protocols

Short-Range Protocols (Personal Area Networks - PAN)

Short-range protocols, primarily used in PANs, include Bluetooth Low Energy (BLE), Zigbee, Thread, and Z-Wave. BLE operates within 10–100 meters on a 2.4 GHz frequency, offering ultra-low power consumption and data rates of 1–2 Mbps, making it ideal for wearables and smart home devices. Zigbee, based on IEEE 802.15.4, provides low-power mesh networking within 10–100 meters and is widely used in home automation such as smart sensors. Thread shares similar characteristics with Zigbee but offers IPv6 support through 6LoWPAN, facilitating IP-based mesh networks like Google Nest. Z-Wave, operating on sub-1 GHz frequencies, ensures minimal interference with data rates between 9.6–100 kbps, making it a preferred choice for smart home security and lighting control.

Medium-Range Protocols (Local Area Networks - LAN)

Medium-range protocols used in LANs include Wi-Fi (IEEE 802.11) and Matter. Wi-Fi, functioning on 2.4 GHz and 5 GHz frequencies, enables high-speed data transfer from 10 Mbps to 10 Gbps (Wi-Fi 6), making it ideal for high-bandwidth IoT applications such as cameras and voice assistants. Matter, a new unified IoT standard, integrates with Wi-Fi and Thread, ensuring interoperability across different smart home brands.

Long-Range Protocols (Wide Area Networks - WAN)

Long-range protocols used in WANs include LoRaWAN, NB-IoT, LTE-M, and Sigfox, providing connectivity over vast distances with minimal power consumption. LoRaWAN supports 2–15 km (rural) and 1–5 km (urban) ranges on sub-1 GHz unlicensed bands, offering very low power and extended battery life, making it suitable for smart agriculture and city sensors. NB-IoT, operating on licensed LTE bands, supports data rates of 20–250 kbps and is ideal for utility meters and asset tracking due to its low power modes (PSM/eDRX). LTE-M, with 1 Mbps data rates, supports voice and SMS, making it useful for fleet tracking and wearables. Sigfox, designed for low-cost and infrequent transmissions, operates on 868 MHz (EU) and 902 MHz (US) frequencies, offering a data rate of 100 bps, making it optimal for applications like alarms and simple monitoring systems.

Comparison Table

Comparison Table

Protocol Range Data Rate Power Topology Key Use Case
BLE 10–100m 1–2 Mbps Ultra-low Star/Mesh Wearables
Zigbee 10–100m 250 kbps Low Mesh Smart home
Wi-Fi 50–100m High High Star Video/voice
LoRaWAN 2–15 km 50 kbps Very low Star-of-stars Agriculture
NB-IoT Cellular 250 kbps Low Cellular Utility meters

My Exciting IoT Learning Journey

This week, I'm learning how to connect my XIAO ESP32C3 microcontroller with a DHT11 sensor to measure temperature and humidity. With chatgpt guidance, I'll be sending this sensor data to two important platforms:

Data Platforms

  • ThingSpeak - A cloud service where I can store and visualize my sensor readings -request over Wi-Fi using the HTTPClient library
  • MQTT Server - For real-time data streaming and IoT messaging
  • Key Learning Objectives

  • Program the ESP32C3 to read sensor data
  • Connect to Wi-Fi networks securely
  • Use API calls to send data to ThingSpeak
  • Publish readings to an MQTT broker
  • I'm particularly excited about seeing my live sensor data appear on web dashboards! This hands-on experience will help me understand practical IoT systems and give me confidence in working with cloud platforms.

    Thingspeak Account

    Steps to Set Up ThingSpeak

    1. Create a ThingSpeak Account

  • Go to ThingSpeak and sign up for a free account.
  • Click on Channels, then select New Channel.
  • Enter the following details:

  • Field 1: Temperature
  • Field 2: Humidity
  • Click Save Channel.
  • 2. Get Your API Key

  • Go to the API Keys section in your channel settings.
  • Copy the Write API Key. You will need this in your code.
  • Note: My channel ID is 2895060.

    3. Upload Code to XIAO ESP32C3

  • Ensure the Write API Key is added to your code.
  • Upload the code to the XIAO ESP32C3 using the Arduino IDE
  • Wiring the XIAO ESP32C3 with DHT11 Sensor

    • Connect the OUT pin of the DHT11 to pin D10 on the XIAO ESP32C3.
    • Connect the Vcc pin of the DHT11 to 3.3V on the XIAO ESP32C3.
    • Connect the GND pin of the DHT11 to GND on the XIAO ESP32C3.
    Description

    Program to upload in the XIAO ESP32C3 using Arduino IDE

    This code reads temperature & humidity using the DHT11 sensor, then uploads the data to ThingSpeak.

     #include 
    #include 
    #include 
    
    #define DHTPIN D10
    #define DHTTYPE DHT11
    
    const char* ssid = "sujith";  // Replace with your Wi-Fi SSID
    const char* password = "123456878";  // Replace with your Wi-Fi password
    const char* apiKey = "OGY3SZJ7ZSFUERU5";  // Replace with your ThingSpeak API Key
    const char* server = "http://api.thingspeak.com/update";
    
    DHT dht(DHTPIN, DHTTYPE);
    
    void setup() {
      Serial.begin(115200);
      WiFi.begin(ssid, password);
      dht.begin();
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("\nConnected to Wi-Fi");
    }
    
    void loop() {
      float temperature = dht.readTemperature();
      float humidity = dht.readHumidity();
    
      if (!isnan(temperature) && !isnan(humidity)) {
        HTTPClient http;
        String url = String(server) + "?api_key=" + apiKey + "&field1=" + String(temperature) + "&field2=" + String(humidity);
        
        http.begin(url);
        int httpResponseCode = http.GET();
        http.end();
    
        Serial.print("Sent Temp: "); Serial.print(temperature);
        Serial.print(" C, Humidity: "); Serial.println(humidity);
      }
    
      delay(15000);  // ThingSpeak allows updates every 15 seconds
    }
    

    After establishment of the code

    ESP32C3 reads DHT11 sensor data and sends temperature & humidity via Wi-Fi HTTP request.ThingSpeak stores the data and visualizes it in graphs.No Serial Communication, Just using Wi-Fi HTTP!

    ESP32 as an HTTP Server- Your XIAO ESP32C3 will act as a web server and serve data over HTTP

    The sensor readings will access using local WiFi network via a browser. uploaded the following code to esp32c3

    #include 
    #include 
    #include 
    
    // Replace with your network credentials
    const char* ssid = "sujith";
    const char* password = "123456878";
    
    // DHT11 setup
    #define DHTPIN D10      // GPIO connected to DHT11 data pin
    #define DHTTYPE DHT11  // DHT 11 sensor type
    DHT dht(DHTPIN, DHTTYPE);
    
    // Create a web server on port 80
    WebServer server(80);
    
    void handleRoot() {
      float temperature = dht.readTemperature();
      float humidity = dht.readHumidity();
    
      // Check for errors
      if (isnan(temperature) || isnan(humidity)) {
        server.send(200, "text/html", "

    Failed to read from DHT sensor!

    "); return; } String html = ""; html += "DHT11 Sensor"; html += "

    DHT11 Sensor Data

    "; html += "

    Temperature: " + String(temperature) + " °C

    "; html += "

    Humidity: " + String(humidity) + " %

    "; html += ""; server.send(200, "text/html", html); } void setup() { // Start serial communication Serial.begin(115200); dht.begin(); // Connect to Wi-Fi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected! IP address:"); Serial.println(WiFi.localIP()); // Define root route server.on("/", handleRoot); // Start the server server.begin(); } void loop() { // Handle incoming client requests server.handleClient(); }
    Description

    After uploading the code, IP address will be generated 192.168.137.41, copied to the webbrowser and see the data in web

    Description

    Problems faced in learning MQTT Protocol

    Tried to Publish Sensor Data to MQTT Server & Mobile App. I have created the hivemq.cloud free account for this progran

      Tried to use Hivemq server, login created and again i m unsuccessful, almost two day i spent with this, i watched so many tutorials, but i m failed to get my results

      Description

      Next to that, Tried to use Node-red , created the dashboard, I m able to upload the code , no error, data is not pushed

      Description Description

      Next to that, Tried to use Adafruit io , created the dashboard, I m able to upload the code , i m not able to push the data,

      Description

      I have spent almost four days on learning different platforms like Node-red, Adafruit, HivemQ, EClipse Mosquito without success. I hope to identify the errors in my code and learn from them as quickly as possible.

    All Proramming Arduino IDE files

    Download source code

    My thingspeak channel ID is 2895060.

    Learned in this week

    Through this Week, I learned how to connect my XIAO ESP32C3 with a DHT11 sensor to send temperature and humidity data to ThingSpeak (a cloud platform for IoT) and an MQTT server (for real-time messaging). With ChatGPT’s guidance, I figured out how to write the code, set up Wi-Fi connections, and use APIs to upload sensor readings. It was exciting to see live data appear on ThingSpeak charts and learned to create MQTT dashboards! This experience helped me understand IoT communication better, and now I feel more confident working with sensors and cloud platforms.

    Happy Learning

    😀 Suith Mayakrishnan 😀