Week 14

Networking and Communications

April 27 2022

Intro to Communication Protocols

- Networking is just copying bits from one place to another
- To split processes up into modules is helpful when you want those processes to run in parallel
- Modularity avoids interference between processes
- Analogy to human speech: language is the protocol layer, the microphone is the physical layer

Protocols, Connectors, Media

- Connectors can be used with different protocols, so an ethernet connector can also be used for serial communication etc.
- Often protocols are nested inside each other, such as WiFi: It has many layers, with the outer layer being the WPA2 encryption
- Information can be transmitted via different media, such as cable, optic, radio frequency

Network Topology

Different possible network topologies.

- A bus topology is very common for wired communication
- With radio communication, a mesh topology is more common. This can help with relaying messages, such as a node relying a message to another recipient
- The network topology is what determines, how a punctual failure impacts the network (such as a single point-of-failure)
- Errors always happen, always relative to the speed and distance. This is why most protocols have error correction built in

Hint: This is why when flashing a microcontroller via serial, take down the speed when transmitting in order to reduce the chance for errors

Wired Communication

Serial vs. parallel communication

- Recap: Ones and zeroes are just changes in voltage in the cable. The change of voltage is agreed upon in the physical protocol
- In serial communication, a byte is sent one bit after the other through the same wire
- In parallel communication, eg. eight wires transmit one bit of the byte in parallel. This enables a much faster communication speed
- When the communication speed of today, serial communication is almost always preferable. This is also related to the price of the physical wires

Synchronous vs. Asynchronous

- Synchronous communication relies on a CLK (clock) signal which defines the timing of the sent messages (such as the baud rate in Arduino)
- Asynchronous communication means that there is no clock line, thus it needs to signal when a message begins and ends
- RX/TX is the most common way of serial communication, it includes a start bit and a stop bit
- It also uses dedicated receive and transmit pins, which have to be wired across
- For Synchronous communication, SPI and I2C are popular protocols

> A lot more notes here

Connecting two ESP32 via Wifi

For the communication and networking homework I teamed up with Tatiana (her documentation here) to make two ESP32s connect via local wifi network. We used an excellent tutorial to to give us a better understanding of the pieces involved. We then modified the tutorials sketches to send a static string of text instead of dynamic sensor readings. This was done to have a simple proof-of-concept, that can easily be expanded on. In the end, it is a matter of how the respective variable(s) on the server side are static or constantly updated. This is what I want to try at home for the next step: Updating a local server according to room temperature readings.

For the two sketches involved, the structure was relatively straight forward . After installing the ESPAsyncWebServer library and Async TCP library (who handle different parts of the server side), we would set up a local wifi network on one ESP32, specifying our SSID and passphrase. For the client side, only the HTTClient library was needed (available via the library manager). For both microcontrollers, of course Wifi.h was additionally loaded in order to interface with the wifi antennas. After that, it was a matter of simply specifying data to be hosted on the server side and retrieving that payload via a HTTP-request on the client side. Printing both outputs helped us to follow the steps and debug any connection problems that arose in the meantime. The resulting infrastructure has an enormous potential, especially in locally defined scenarios, such as smart home automation schemes.

After logging into the wifi of the ESP32 server, the output string can be read under the ESP's IP address (left). On the client side, the same string is received and printed into the serial monitor (right).

A visual representation of the two ESPs talking to each other.

Interfacing with a Server via API

To further practice networking between computers, I wrote a Python script that interfaces with OpenAI GPT3 API to generate short stories after scraping keywords from the internet. The script opens the URL of the API endpoint, and sends the AUTH token as identification. After receiving a positive confirmation, we can send prompts to GPT3. A couple of seconds after we send an API call, specifying the prompt and a dozen other parameters, we get a response back in JSON format. The format is nested into lists and libraries, so one API answer can carry multiple sets of data, all with their individual associated parameters. By parsing the respective lists in the JSON response, we can then extract our GPT3-generated text.

The user interface consists of the command line prompting the user to input the starting URL and the number of jumps. More on the project can be found here.

Further Links

Networking and Communications
purposes
  location
  parallelism
  modularity
  interference

wired
  asynchronous
     RS-232, RS-422, RS-485 MPCM
     ATtiny45
        components video
        hello.bus.45.bridge board traces interior
        hello.bus.45.node board traces interior
        hello.bus.45.c makefile
     ATtiny412
  hop-count
     chip LED strip
  SPI
     MISO/MOSI, CIPO/COPI
        master/secondary, controller/peripheral
     library bit-bang
     (*)RAM
        ESP-PSRAM64H
     SD memory cards
        specification FAT library
        hello.uSD.D11C board components traces interior
           hello.uSD.D11C.ino video
        hello.uSD.44 board components traces interior
           hello.uSD.44.read.c make output
  I2C
     Qwiic STEMMA
     hardware software
     hello.I2C.t1614 board components traces interior
        hello.I2C.ino video
  USB
     ASF HID MIDI Host
  Ethernet
     chip module
  CAN, LIN
  MODBUS
  DMX

OSI layers
  7: application (HTTP)
  6: presentation (SSL)
  5: session (RPC)
  4: transport (TCP, UDP)
  3: network (IP)
  2: data link (MAC)
  1: physical (PHY)

physical media
  capacity
     bandwidth * log_2 (signal/noise)
  wired
     single-ended, differential, powerline
     open collector, open drain
     transmission (pass) gate, tri-state
     transmission line
     waveguide
     SONET optical fiber
  wireless
     RF
        FCC Part 15 ISM
        802.11 Wi-Fi
        802.15 ZigBee 6LoWPAN
        Bluetooth BLE GATT GAP UUID Services app stack
     optical
        transmitter receiver LiFi
     acoustic

modulation
  PCM: Pulse-Code Modulation
  PPM: Pulse-Position Modulation
  OOK: On-Off Keying
  FSK: Frequency-Shift Keying
  BPSK: Binary Phase-Shift Keying
  QAM: Quadrature Amplitude Modulation
  OFDM: Orthogonal Frequency-Division Multiplexing
  FHSS: Frequency-Hopping Spread Spectrum
  DSSS: Direct-Sequence Spread Spectrum
  UWB:  Ultra-WideBand

channel sharing
  ALOHA
  Master-Secondary
  Token Ring
  TDMA: Time-Division Multiple Access
  FDMA: Frequency-Divsion Multiple Access
  CSMA: Carrier-Sense Multiple Access
     CD: Collision Detection
     CA: Collision Avoidance
     1-persistent: transmit when clear
     nonpersistent: random backoff
     p-persistent: probability to transmit
  CDMA: Code-Division Multiple Access
  MIMO: Multiple-Input Multiple-Output
  "PDMA": Physical-Division Multiple Access

errors
  detection, correction
  block, convolution codes
  parity, checksum, Hamming, Reed-Solomon, Turbo

networking
  Internet protocols
     RFCs
     IPv4, IPv6
        unrouted, routed, unicast, multicast, broadcast addresses
     DNS DHCP NAT PAT private
     UDP, TCP
     HTTP
     BGP AODV ROLL
     sockets
        udpsnd.js udprcv.js video
        udpsnd.py udprcv.py
        udpsnd.c udprcv.c
     Wireshark
     SLIP
        slattach route
        hello.bus.45.SLIP.c makefile udp_slip.py video

wireless
  radios
     oscillator, mixer, PA, LNA, IF, I/Q, demod, baseband, filters
  antennas
     Q, antenna gain, impedance matching, short antennas
     FabFi
  single-chip
     MFRC522 (13.56 MHz RFID)
        chip module library security
           hello.MFRC522.t1614 board components traces interior video
     nRF905 (433/868/915 MHz ISM)
        chip module library
     nRF24L01+ (2.4 GHz ISM)
        chip module library project antennas
        hello.nRF24L01P.44 board components traces interior
     RN4871 (2.4 GHz Bluetooth)
        chip module commands
        hello.RN4871.ftdi board components traces interior video
     CC2541 (2.4 GHz Bluetooth)
        chip HC-08 HM-10 HM-11 commands
        hello.HM-11.ftdi board components traces interior video
     nRF52 (2.4 GHz Bluetooth, ISM)
        chip module project project
     CYW43438 (2.4 GHz, Wi-Fi, Bluetooth, FM)
        chip module board
     RFM95/6/7/8 (433/470/868/915 MHz LoRa)
        chip module LoRaWAN
     SX1276 (137-1050 MHz LoRa)
        chip board ExpressLRS
     SIM800L (GSM)
        module
     ESP8266 (2.4 GHz Wi-Fi)
        chip module board power
           hello.ESP-01 board components traces holes interior
              Web server video
           hello.ESP-WROOM-02D board components traces holes interior
              Access point video
     ESP32 (2.4 GHz Wi-Fi, Bluetooth)
        chip module board pins power
           hello.ESP32-WROOM board components traces holes interior
              Web client video
              Web server video
              UDP video
              Bluetooth serial video
              802.11 LR
           hello.ESP32-CAM board components traces holes interior
              camera video
  software radio
  OpenWrt

assignment
  individual assignment:
     design, build, and connect wired or wireless node(s)
     with network or bus addresses
  group assignment:
     send a message between two projects