Coder Social home page Coder Social logo

ersushantsood / cbor-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaredwolff/cbor-example

0.0 1.0 0.0 16 KB

Example how to use CBOR for embedded projects in conjunction with a Rust web server.

License: BSD 3-Clause "New" or "Revised" License

C 67.95% Rust 27.22% CMake 4.84%

cbor-example's Introduction

CBOR Example using Rust and C

This repository is an example from the blog post on jaredwolff.com.

Building the Rust server

Already assuming you have Rust installed (rustup is recommended)

Then run

cargo run

This will build and run your server. When ready you'll see:

cbor-example on  master [+?] is 📦 v0.1.0 via 🦀 v1.47.0 
❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.48s
     Running `target/debug/cbor-example`

Building the C code

If youh haven't already make sure you pull the submodule(s) for this project using:

> git submodule update --init

Also, this code does use cmake please be sure to install before you continue. You should also have curl installed.

> brew install cmake curl

My example above uses Homebrew for OSX. You should install per your OS recommended package manager.

Once installed

> cd client
❯ cmake .
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jaredwolff/Git/cbor-example/client

Then build it

❯ cmake --build .
Scanning dependencies of target client
[ 12%] Building C object CMakeFiles/client.dir/main.c.o
[ 25%] Building C object CMakeFiles/client.dir/src/telemetry_codec.c.o
[ 37%] Building C object CMakeFiles/client.dir/lib/QCBOR/src/UsefulBuf.c.o
[ 50%] Building C object CMakeFiles/client.dir/lib/QCBOR/src/ieee754.c.o
[ 62%] Building C object CMakeFiles/client.dir/lib/QCBOR/src/qcbor_decode.c.o
[ 75%] Building C object CMakeFiles/client.dir/lib/QCBOR/src/qcbor_encode.c.o
[ 87%] Building C object CMakeFiles/client.dir/lib/QCBOR/src/qcbor_err_to_str.c.o
[100%] Linking C executable client
[100%] Built target client

Then run it with:

> ❯ ./client 
Start of QCBOR Example

You should see an instant response on the other side:

Message from id: 1234
Telemetry: TelemetryData { version: "0.1.0", rssi: -49 }

Well done! You did it!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.