Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1750741409, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ { "schema":"libjg2-1", "oid":{ "oid": "47efb8c1c2371fa309f85a32984e99b2cc1d614a", "alias": [ "refs/heads/main"]},"tree": [ { "name": "CMakeLists.txt","mode": "33188", "size":1723}, { "name": "README.md","mode": "33188", "size":9779}, { "name": "binance-ss.c","mode": "33188", "size":5125}, { "name": "get-ss.c","mode": "33188", "size":1600}, { "name": "helpers.c","mode": "33188", "size":3068}, { "name": "libwebsockets","mode": "40960", "size":11}, { "name": "main.c","mode": "33188", "size":2790}, { "name": "pico_sdk_import.cmake","mode": "33188", "size":2763}, { "name": "private.h","mode": "33188", "size":1074}, { "name": "system.c","mode": "33188", "size":2961}, { "name": "transport-serial.c","mode": "33188", "size":7081}],"s":{"c":1750682707,"u": 2135}} ,{"schema":"libjg2-1", "cid":"8e7b851c6a404ecc952ee0e6292fe0cb", "oid":{ "oid": "47efb8c1c2371fa309f85a32984e99b2cc1d614a", "alias": [ "refs/heads/main"]},"blobname": "minimal-examples/embedded/pico/pico-sspc-binance/README.md", "blob": "# Pico binance via SSPC / serial transport Example\n\nThis is a project for an RPi pico, a cheap, widely available US$4 networkless\n133MHz Cortex M0 embedded SBC.\n\nIt is designed to run Serialized Secure Streams in a transport mux over\na UART running at 2Mbps, and demo two streams concurrently.\n\n![](../../../../doc-assets/rpi-uart-1.png)\n\n## Traffic on the UART link\n\nThe UART link has a lws_transport_mux layer that detects link up and down, and\nabove that Serialized SS travels in each mux channel.\n\n1) Mux framing PING / PONG / PONGACK / link detect, channel open / close etc\n\n2) SS to Binance compressed wss server\n\nThe pico runs the generic lws SS binance client and from around 30 messages a\nsecond, reports the average price of bitcoin in realtime once a second,\nsame as it does if you run it on a PC and using the same SS code.\n\n3) Every 5s another SS does a GET from https://warmcat.com/index.html to\ndemonstrate multiple SS muxing over the UART.\n\nThat involves compressed wss and h2, but the pico has:\n\n - no network stack (TCP/IP)\n - no tls\n - no h2\n - no wss protocol library\n - no wss compression extension\n \nThe pico creates a generic SS using the same code as the other examples, the\ncompressed wss connection is actually fulfilled by the proxy part (lws-minimal-\nsecure-streams-custom-proxy-transport) connected over the UART. It passes\nthe bursty 20 - 120 KBytes/sec SS payloads over the UART where the binance\nSS client consumes them as if it was all happening on the pico.\n\n## Hookup\n\n![](../../../../doc-assets/rpi-uart.png)\n\nThe three pins shown above need connecting to an FTDI-based\n3.3V UART - USB adapter.\n\nFTDI is needed because we will run the link at 2Mbps, most cheaper adapters\ndon't support this baud rate.\n\nFor this demo 2Mbps is required, since the websocket data from binance is very\nbursty, we have to be able to clear a burst before the next one in order to\nkeep up.\n\n## Build\n\nThis builds as a toplevel project using the pcio sdk, it builds\nlws via a symlink, and links with libwebsockets.a built with `-DLWS_ONLY_SSPC`\n\nAdapt `PICO_SDK_PATH` below to where your pico sdk is installed\n\n```\n$ cmake .. -DPICO_SDK_PATH\u003d/projects/pico-sdk\n$ make\n```\n\nYou flash the pico by holding down the button and inserting USB, it mounts as a\nUSB storage device. Copy `pico-sspc-binance.uf2` to the storage device and\nunmount it.\n\n## Running\n\nOn the PC, you need to build `lws-minimal-ssproxy-custom-transport-uart`, from\n`./minimal-examples/ssproxy/ssproxy-custom-transport-uart`,\nwhich needs lws built with `-DLWS_WITHOUT_EXTENSIONS\u003d0`. This connects to\n`/dev/ttyUSB0` and starts the mux + SS Proxy.\n\nOn the Pico, you can monitor the serial console over USB to see logs via\n`/dev/ttyACM0`, it's a bit awkward since that is created during Pico boot, so\nyou miss the earliest logs, but the app on the Pico won't do anything\ninteresting until it connects via the proxy, and shows periodic pings on the\nmux layer until then.\n\nWait for peer (1Hz pings at mux layer)\n\n```\n11010626: lws_transport_mux_retry_connect\n11010856: lws_transport_path_client_dump: lws_transport_mux_retry_connect: MUX: 2000AC80, IN: ops\u003dtxp_inside_sspc, priv\u003d2000AD80, ONW: ops\u003dtxpmuxc, priv\u003d00000000\n11011109: lws_transport_mux_retry_connect: transport not operational\n12004542: sul_ping_cb: issuing ping\n12004802: lws_transport_path_client_dump: cpath: MUX: 00000000, IN: ops\u003dtxpmuxc, priv\u003d2000AC80 (IsTM), ONW: ops\u003dtxpserial, priv\u003d00000000\n12005055: txp_serial_write: writing 9\n12005287: 0000: F6 00 00 00 00 00 B7 2D 54 .......-T \n12005441: \n12011287: lws_sspc_sul_retry_cb\n12011438: lws_transport_mux_retry_connect\n12011692: lws_transport_path_client_dump: lws_transport_mux_retry_connect: MUX: 2000AC80, IN: ops\u003dtxp_inside_sspc, priv\u003d2000AD80, ONW: ops\u003dtxpmuxc, priv\u003d00000000\n12011935: lws_transport_mux_retry_connect: transport not operational\n13012121: lws_sspc_sul_retry_cb\n13012256: lws_transport_mux_retry_connect\n13012492: lws_transport_path_client_dump: lws_transport_mux_retry_connect: MUX: 2000AC80, IN: ops\u003dtxp_inside_sspc, priv\u003d2000AD80, ONW: ops\u003dtxpmuxc, priv\u003d00000000\n13012796: lws_transport_mux_retry_connect: transport not operational\n```\n\nGet mux layer `PING` from proxy / mux side, return PONG\n\n```\n13941468: lws_transport_mux_rx_parse: got PING\n13941779: lws_transport_path_client_dump: cpath: MUX: 00000000, IN: ops\u003dtxpmuxc, priv\u003d2000AC80 (IsTM), ONW: ops\u003dtxpserial, priv\u003d00000000\n13942054: txp_serial_write: writing 17\n13942323: 0000: F7 00 00 00 00 00 00 00 00 00 00 00 00 00 D4 BB ................\n13942578: 0010: 98 . \n13942738: \n```\n\nGet mux later `PONGACK` (three way PING) response, both sides are up at mux layer.\nThis also provides the peer with the proxy device's time in us resolution.\n\n```\n13955788: lws_transport_mux_rx_parse: got PONGACK: ustime 1630898701380539\n13956011: lws_transport_set_link: ******* transport mux link is UP\n```\n\nRetry the SS link to proxy at SSS layer, first request open mux channel\n\n```\n14012976: lws_sspc_sul_retry_cb\n14013133: lws_transport_mux_retry_connect\n14013356: lws_transport_path_client_dump: lws_transport_mux_retry_connect: MUX: 2000AC80, IN: ops\u003dtxp_inside_sspc, priv\u003d2000AD80, ONW: ops\u003dtxpmuxc, priv\u003d00000000\n14013723: lws_transport_mux_retry_connect: added channel\n14014026: lws_transport_path_client_dump: cpath: MUX: 00000000, IN: ops\u003dtxpmuxc, priv\u003d2000AC80 (IsTM), ONW: ops\u003dtxpserial, priv\u003d00000000\n14014286: txp_serial_write: writing 2\n14014471: 0000: F0 FF .. \n14014702: \n```\n\nReceive mux channel open ACK, mux channel ready on both sides, start to issue\nSerialized Secure Streams in it: request binance SS stream\n\n```\n14019481: lws_transport_mux_rx_parse: ch 255 fully open\n14019661: 0\n14019880: lws_sspc_txp_tx: LPCSCLI_SENDING_INITIAL_TX\n14020118: lws_transport_mux_write: 19\n14020280: txp_serial_write: writing 23\n14020553: 0000: F5 FF 00 13 AA 00 10 01 FF FF FF FF 1D CD 65 00 ..............e.\n14020838: 0010: 62 69 6E 61 6E 63 65 binance \n14020995: \n14037838: (unset) -\u003e LWSSSCS_CREATING\n```\n\nSS states move forward as proxy fulfils the onward connection, then starts to\nreceive SSS payloads (previously compressed wss message payloads) and report\nsummaries at 1Hz\n\n```\n15090846: LWSSSCS_CREATING -\u003e LWSSSCS_CONNECTING\n15091150: LWSSSCS_CONNECTING -\u003e LWSSSCS_CONNECTED\n16091462: sul_hz_cb: price: min: 5170001¢, max: 5170867¢, avg: 5170245¢, (26 prices/s)\n16091795: sul_hz_cb: elatency: min: 137ms, max: 296ms, avg: 203ms, (26 msg/s, 49 KiBytes/s SS RX)\n17091455: sul_hz_cb: price: min: 5169104¢, max: 5170101¢, avg: 5169602¢, (33 prices/s)\n17091746: sul_hz_cb: elatency: min: 139ms, max: 304ms, avg: 173ms, (33 msg/s, 94 KiBytes/s SS RX)\n18091450: sul_hz_cb: price: min: 5169104¢, max: 5171400¢, avg: 5169304¢, (30 prices/s)\n18091749: sul_hz_cb: elatency: min: 134ms, max: 167ms, avg: 139ms, (30 msg/s, 31 KiBytes/s SS RX)\n19091460: sul_hz_cb: price: min: 5169183¢, max: 5169370¢, avg: 5169204¢, (29 prices/s)\n19091753: sul_hz_cb: elatency: min: 136ms, max: 152ms, avg: 139ms, (29 msg/s, 31 KiBytes/s SS RX)\n20091468: sul_hz_cb: price: min: 5169183¢, max: 5171063¢, avg: 5169664¢, (29 prices/s)\n20091791: sul_hz_cb: elatency: min: 136ms, max: 151ms, avg: 139ms, (29 msg/s, 30 KiBytes/s SS RX)\n21091482: sul_hz_cb: price: min: 5169183¢, max: 5171574¢, avg: 5169377¢, (30 prices/s)\n21091759: sul_hz_cb: elatency: min: 136ms, max: 151ms, avg: 139ms, (30 msg/s, 44 KiBytes/s SS RX)\n22091477: sul_hz_cb: price: min: 5168614¢, max: 5170771¢, avg: 5169225¢, (30 prices/s)\n22091772: sul_hz_cb: elatency: min: 135ms, max: 148ms, avg: 139ms, (30 msg/s, 54 KiBytes/s SS RX)\n23091491: sul_hz_cb: price: min: 5169058¢, max: 5169276¢, avg: 5169122¢, (28 prices/s)\n23091772: sul_hz_cb: elatency: min: 136ms, max: 144ms, avg: 138ms, (28 msg/s, 22 KiBytes/s SS RX)\n...\n```\n\nThe periodic second SS reads from https://warmcat.com look like this (it dumps the first and\nlast 16 bytes of the rx packet)\n\n```\n42214221: lws_sspc_deserialize_parse: [mintest-lws|1]: : CONNECTED mintest-lws\n42214520: lws_ss_serialize_state_transition: [mintest-lws|1]: : LPCSCLI_LOCAL_CONNECTED -\u003e LPCSCLI_OPERATIONAL\n42214849: lws_ss_check_next_state_sspc: [mintest-lws|1]: : LWSSSCS_CONNECTING -\u003e LWSSSCS_CONNECTED\n42215248: get_state: [mintest-lws|1]: : LWSSSCS_CONNECTED (5), ord 0x0\n42220399: get_rx: [mintest-lws|1]: : RX 1520, flags 0x1\n42220862: : 0000: 3C 21 44 4F 43 54 59 50 45 20 68 74 6D 6C 3E 0A \u003c!DOCTYPE html\u003e.\n42221074: : \n42221370: : 0000: 3C 6C 69 3E 38 30 20 6D 69 6E 69 6D 61 6C 20 65 \u003cli\u003e80 minimal e\n42221580: : \n42305323: get_rx: [mintest-lws|1]: : RX 1520, flags 0x0\n42305900: : 0000: 78 61 6D 70 6C 65 73 3A 20 3C 61 20 68 72 65 66 xamples: \u003ca href\n42306152: : \n42306411: : 0000: AD 98 3C 2F 74 64 3E 3C 74 64 20 63 6C 61 73 73 ..\u003c/td\u003e\u003ctd class\n42306717: : \n42343404: get_rx: [mintest-lws|1]: : RX 1520, flags 0x0\n42343967: : 0000: 3D 22 67 22 3E E2 AD 98 3C 2F 74 64 3E 3C 2F 74 \u003d\u0022g\u0022\u003e...\u003c/td\u003e\u003c/t\n42344184: : \n42344412: : 0000: 77 65 62 73 6F 63 6B 65 74 73 2F 74 72 65 65 2F websockets/tree/\n42344618: : \n42486791: get_rx: [mintest-lws|1]: : RX 1520, flags 0x0\n42487366: : 0000: 6C 69 62 2F 65 76 65 6E 74 2D 6C 69 62 73 22 20 lib/event-libs\u0022 \n42487635: : \n42487894: : 0000: 31 36 20 69 62 22 3E 0A 20 20 20 20 20 3C 68 31 16 ib\u0022\u003e. \u003ch1\n42488113: : \n42527399: get_rx: [mintest-lws|1]: : RX 1277, flags 0x0\n42527903: : 0000: 3E 51 41 3C 2F 68 31 3E 0A 20 20 20 20 20 20 4C \u003eQA\u003c/h1\u003e. L\n42528116: : \n42528404: : 0000: 3C 2F 62 6F 64 79 3E 0A 3C 2F 68 74 6D 6C 3E 0A \u003c/body\u003e.\u003c/html\u003e.\n42528637: : \n42570288: get_rx: [mintest-lws|1]: : RX 0, flags 0x2\n```\n","s":{"c":1750682707,"u": 950}} ],"g": 1973,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "7d0a"}