notes.org
1 #+title: Notes 2 3 [[https://www.youtube.com/watch?v=ReNqPp3EmYk][Books That Made Me A CRACKED Backend Dev - YouTube]] 4 5 [[https://www.youtube.com/watch?v=-XPrSScamXc][Optimizing Arduino Code: no setup(), no loop() ⛔ - YouTube]] 6 7 [[https://www.youtube.com/watch?v=qOW1KvSEfLs][SQLite is a masterclass in library design - YouTube]] 8 9 * PlatformIO 10 11 #+begin_src sh 12 ssh -fCo "ExitOnForwardFailure yes" -L 54333:localhost:54321 mfarabi@rpi5-16 "nc -l localhost 54321 </dev/ttyUSB0 >/dev/ttyUSB0" && socat pty,link=$DEVENV_ROOT/ttyUSB0,wait-slave tcp:localhost:54333 & 13 #+end_src 14 15 #+begin_src sh 16 pio device monitor -p ttyUSB0 17 #+end_src 18 19 #+begin_src sh 20 killall ssh 21 #+end_src 22 23 #+begin_src sh 24 espflash monitor -p /dev/ttyUSB0 --non-interactive 25 #+end_src 26 27 #+begin_src sh 28 sudo apt install usbip 29 sudo modprobe vhci-hcd 30 sudo modprobe usbip-core 31 sudo modprobe usbip-host 32 sudo usbip list -l 33 sudo usbip bind -b 3-1 34 sudo usbipd 35 #+end_src 36 37 - [[https://stats.uptimerobot.com/ZWBXVu5NGx][UptimeRobot stats]] 38 - [[https://docs.platformio.org/en/latest/projectconf/interpolation.html][PlatformIO interpolation]] 39 - [[https://docs.platformio.org/en/latest/projectconf/sections/env/options/advanced/index.html][PlatformIO advanced env options]] 40 - [[https://community.platformio.org/t/different-spiffs-images-for-different-build-environments/4845][Different SPIFFS images per env]] 41 - [[https://docs.platformio.org/en/latest/advanced/unit-testing/structure/hierarchy.html#unit-testing-test-hierarchy][PlatformIO unit test hierarchy]] 42 43 # ssl:host=remote.platformio.org:port=4413 44 45 ** Registry API :verb: 46 template https://api.registry.platformio.org/v3 47 Accept: application/json 48 49 *** Packages 50 get /search?query=ArduinoJson 51 52 ** Accounts API :verb: 53 template https://api.accounts.platformio.org/v1 54 Accept: application/json 55 Authorization: Bearer {{(getenv "PLATFORMIO_AUTH_TOKEN")}} 56 # https://github.com/platformio/platformio-core/blob/73d9f3dbea809f337bdee5be495f4d3b896deef0/platformio/account/client.py#L18 57 58 *** Profile 59 get /profile 60 61 *** Summary 62 get /summary 63 64 *** Orgs 65 :properties: 66 :Verb-Store: orgs-response 67 :end: 68 get /orgs 69 70 **** Owners 71 get /{{(verb-json-get (oref (verb-stored-response "orgs-response") body) 0 'orgname)}}/owners 72 73 **** Teams 74 get /{{(verb-json-get (oref (verb-stored-response "orgs-response") body) 0 'orgname)}}/teams 75 76 77 * Inline Org Commands 78 79 #+begin_src sh :dir /ssh:rpi5-16: 80 echo hello 81 #+end_src 82 83 * Terminology 84 85 | *Term* | *🎨 Color* | Abbreviation / Signal Name* | *Bus Type* | *Direction (ESP32 POV)* | *Definition / Purpose* | 86 |---------------+-------------------+----------------------------------------+-----------------------+--------------------------+-------------------------------------------------------| 87 | =*I²C*= | | Inter-Integrated Circuit | | | Two-wire serial bus for sensors and chips. | 88 | =SDA= | Blue | Serial Data | I²C | ⇄ Bidirectional | Carries data between master and slaves. | 89 | =SCL= | Yellow | Serial Clock | I²C | → Output (master→slaves) | Provides timing for data bits. | 90 | =ADDR= / =SDO= | Brown | Address Select | I²C Sensors | — | Chooses device I²C address (tie to GND or 3V3). | 91 | =INT= | Orange | Interrupt | I²C / Sensors | ← Input to ESP32 | Alert pin signaling “data ready” or “event”. | 92 | | | | | | | 93 | =*SPI *= | | Serial Peripheral Interface | | | Four-wire high-speed bus for displays, SD cards, etc. | 94 | =SCK/CLK= | Yellow | Serial Clock / Clock Line | SPI | → Output | Clock generated by master for sync. | 95 | =SO/MISO= | Green | Master In Slave Out | SPI | ← Input | Data returned from device to master. | 96 | =SI/MOSI= | Blue | Master Out Slave In | SPI | → Output | Data sent from master (ESP32) to device. | 97 | =CS/SS= | White | Chip Select / Slave Select | SPI | → Output | Chooses which device is active (LOW = selected). | 98 | =DET= | Purple | Card Detect | SPI / SD | ← Input (optional) | Signals when SD card inserted. | 99 | =WP= | Gray | Write Protect | SPI / SD | ← Input (optional) | Indicates SD card lock switch state. | 100 | | | | | | | 101 | =*UART*= | | Serial Text Link | | | Two-wire asynchronous serial communication. | 102 | =TX= | Orange | Transmit | UART | → Output | Sends serial data to another device. | 103 | =RX= | Green | Receive | UART | ← Input | Receives serial data from another device. | 104 | | | | | | | 105 | =*Display*= | | | | | | 106 | =VGA= | Blue/Green/Red | Video Graphics Array | Parallel RGB (Analog) | → Output | Sends analog RGB + sync signals to legacy monitors. | 107 | =HDMI= | Black | High-Definition Multimedia Interface | TMDS (Serial) | → Output | Digital audio/video link for modern displays. | 108 | =LVDS= | Gray Twisted Pair | Low-Voltage Differential Signaling | Differential Serial | → Output | High-speed digital display link (used in laptops). | 109 | =OLED= | — | Organic Light Emitting Diode | SPI / I²C | → Output | Small low-power display panel for text/graphics. | 110 | =TFT= | — | Thin-Film Transistor (LCD type) | SPI / Parallel | → Output | Color LCD display used in dev boards. | 111 | =PWM= | Yellow | Pulse Width Modulation | GPIO (timed) | → Output | Simulates analog voltage (e.g., LED dimming, motors). | 112 | | | | | | | 113 | =*Memory*= | | | | | | 114 | =EEPROM= | — | Electrically Erasable Programmable ROM | I²C / SPI | ⇄ | Non-volatile storage for small configs. | 115 | =FLASH= | — | — | SPI / QSPI | ⇄ | Non-volatile main storage for firmware. | 116 | =SRAM= | — | Static Random Access Memory | Parallel | ⇄ | Fast temporary working memory. | 117 | =DIMM= | Green | Dual Inline Memory Module | DDR / SDRAM | ⇄ | Removable RAM sticks (PCs). | 118 | =SD= | — | Secure Digital | SPI / SDIO | ⇄ | Removable flash storage card. | 119 | | | | | | | 120 | =*Peripherals*= | | | | | | 121 | =PCI= | — | Peripheral Component Interconnect | Parallel | ⇄ | Expansion bus for peripherals (legacy). | 122 | =PCIe= | — | PCI Express | High-Speed Serial | ⇄ | Modern version of PCI; used for GPUs, Wi-Fi, etc. | 123 | =USB= | White/Green | Universal Serial Bus | Differential Serial | ⇄ | Connects peripherals, keyboards, storage, etc. | 124 | =CAN= | Gray Twisted Pair | Controller Area Network | Differential | ⇄ | Robust automotive/industrial communication bus. | 125 | =GPIO= | — | General Purpose Input/Output | — | ⇄ | Simple programmable digital pin. | 126 | | | | | | | 127 | =*Networking*= | | | | | | 128 | =ETH= | Orange/Green | Ethernet | RMII / MII | ⇄ | Wired networking interface. | 129 | =Wi-Fi= | — | — | RF (2.4 / 5 GHz) | ⇄ | Wireless networking. | 130 | =BLE= | — | Bluetooth Low Energy | RF (2.4 GHz) | ⇄ | Short-range low-power radio link. | 131 | =Antenna= | Copper | ANT | RF | → / ← | Sends or receives radio waves. | 132 | | | | | | | 133 | =*Utility*= | | | | | | 134 | =ADC= | — | Analog-to-Digital Converter | Internal / GPIO | ← Input | Reads analog voltages as digital values. | 135 | =DAC= | — | Digital-to-Analog Converter | Internal / GPIO | → Output | Outputs analog voltages. | 136 | =RST= | White | Reset | GPIO | ← Input | Resets MCU when pulled low. | 137 | =BOOT= | Blue | Boot Mode | GPIO | ← Input | Selects firmware download mode. | 138 | =3V3= / =VCC= | Red | Power Supply | All | — | 3.3 V output from ESP32 to power sensors. | 139 | =GND= | Black | Ground | All | — | Electrical reference (0 V). | 140 | =DFU= | | Direct Firmware Update | | | | 141 142 - =IOC= - Interrupt on Change 143 - Feature to detect when a GPIO pin changes state (low→high or high→low) and trigger an interrupt so the CPU can respond immediately instead of constantly polling the pin. 144 - Buttons, switches, or any digital input where you want to react instantly to a change. 145 - You configure a pin to generate an interrupt on a rising edge, falling edge, or both edges. When the event occurs, the NVIC (Nested Vectored Interrupt Controller) triggers an interrupt service routine (ISR). 146 - Saves CPU cycles because you don’t need to constantly check pin status. The MCU just “wakes up” when something changes. 147 - STM32 HAL, this is typically set up via functions like HAL_GPIO_EXTI_Callback() after enabling the pin’s EXTI (External Interrupt) line. 148 149 - [[https://www.arduino.cc][Arduino]] 150 - [[https://www.arduino.cc/en/software/][IDE]] 151 - [[https://docs.arduino.cc/arduino-cli/][CLI]] 152 153 - [[https://www.espressif.com][Espressif]] 154 - [[https://idf.espressif.com][IDF]] 155 156 [[https://www.st.com/content/st_com/en.html][STM32]] 157 - [[https://www.st.com/en/development-tools/stm32cubeide.html][CubeIDE]] 158 - [[https://www.st.com/en/development-tools/stm32cubemx.html][CubeMX]] 159 - [[https://www.st.com/en/development-tools/stm32cubeprog.html][CubeProgrammer]] 160 - [[https://www.st.com/resource/en/user_manual/um3088-stm32cube-commandline-toolset-quick-start-guide-stmicroelectronics.pdf][Guide]] 161 - [[https://www.st.com/en/development-tools/stm32cubeclt.html][CubeCLT]] 162 - [[https://www.st.com/en/development-tools/st-link-server.html][ST-Link Server]] 163 - [[https://www.st.com/en/development-tools/st-link-v2.html][ST-LINK]] 164 - [[https://www.st.com/resource/en/user_manual/um1075-stlinkv2-incircuit-debuggerprogrammer-for-stm8-and-stm32-stmicroelectronics.pdf][User Manual]] 165 166 [[https://www.ros.org][ROS]] 167 - Install via [[https://pixi.sh/latest/][Pixi]] 168 169 - [[https://en.wikipedia.org/wiki/LoRa][LoRaWan]] 170 - [[https://www.chirpstack.io][ChirpStack]] 171 172 - ultra low power 173 - long range 174 - deep indoor penetration 175 - license-free spectrum 176 - geolocation 177 - public & private deployments 178 - end-to-end security 179 - firmware updates over the air 180 - certification program 181 - ecosystem 182 183 184 - use cases 185 - natural disaster prevention 186 - smart agriculture & animal production monitoring 187 - endangered species protection 188 - smart industry control 189 - smart cities, homes, buildings, & offices 190 - supply chain logistics, asset tracking, & quality management 191 - smart metering facilities (water, gas, electricity) 192 193 - network coverage 194 - *150 countries* with deployments, *150 LoRaWAN network operators* 195 196 197 - network architecture 198 - end nodes - LoRa RF LoRaWAN 199 - pet tracking 200 - smoke alarm 201 - water meter 202 - vending machine 203 - trash container 204 - concententrator/gateway - TCP/IP SSL LoRaWAN 205 - network server - 3G/Ethernet Backhaul 206 - application server - TCP/IP SSL Secure Payload 207 208 209 - what's the difference? 210 - LoRaWAN - mac layer (MAC) 211 - mac options 212 - class A, B, C 213 - LoRa - physical layer (PHY) 214 - LoRa modulation 215 - Regional ISM Band 216 - EU 868, EU 433, US 915, AS 430, ... 217 218 219 - Modbus is built on top of RS 485 and has pauses in messages 220 - Maximum amount of messages can be spammed through RS-485 221 222 * By example 223 224 - =Statements=: instructions that perform some action and do not return a value 225 - =Expressions=: evaluate to a resultant value 226 227 ** [[https://www.cbyexample.com][C]] 228 229 *** Keywords 230 1. auto 231 2. break 232 3. case 233 4. char 234 5. const 235 6. continue 236 237 7. default 238 8. do 239 9. double 240 10. else 241 11. enum 242 12. extern 243 13. float 244 14. for 245 246 15. goto 247 16. if 248 17. int 249 18. long 250 19. register 251 20. return 252 253 21. short 254 22. signed 255 23. sizeof 256 24. static 257 25. struct 258 26. switch 259 260 27. typedef 261 28. union 262 29. unsigned 263 30. void 264 31. volatile 265 32. while 266 267 *** Data Types 268 1. char 269 2. int 270 3. float 271 4. double 272 5. void 273 274 *** Examples 275 - Hello World 276 #+begin_src C :results output 277 #include <stdio.h> 278 279 int main(){ 280 printf("Hello World!\n"); 281 return 0; 282 } 283 #+end_src 284 285 #+begin_src C :includes <stdio.h> :results output 286 int main() { 287 printf("Hello, World!\n"); 288 return 0; 289 } 290 #+end_src 291 292 #+begin_src C++ :includes '(<iostream> <stdio.h>) :results output 293 std::cout<<"Hello World!\n"; 294 printf("%d\n", 2+2); 295 #+end_src 296 297 - Types 298 - Every variable has an associated data type that defines its data storage format. Each type requires a certain amount of memory and permits a relevant set of operations. 299 300 #+begin_src C :results output 301 #include <stdbool.h> //for bool 302 303 int main(){ 304 int a; // Integer 305 unsigned int b; // Unsigned integers only store positive numbers. As a result, they have a higher positive range. 306 char c; // Character 307 short d; // Short integer 308 long e; // Long integer 309 float f; // Floating point integer 310 double g; // 311 bool h; // Boolean TRUE or FALSE 312 return 0; 313 } 314 #+end_src 315 316 - Threads 317 318 #+begin_src C :results output 319 #include <stdio.h> 320 #include <pthread.h> 321 322 void* thread_func(void* arg){ 323 printf("Printing from Thread\n"); 324 return NULL; 325 } 326 327 int main() { 328 pthread_t thread_id; 329 pthread_create(&thread_id, NULL, thread_func, NULL); 330 pthread_join(thread_id, NULL); // Wait for thread to return before continuing execution 331 printf("Thread returned\n"); 332 return 0; 333 } 334 #+end_src 335 336 #+RESULTS: 337 : Printing from Thread 338 : Thread returned