Coder Social home page Coder Social logo

efmq's Introduction

Ethernet Frames Message Queue (EFMQ)

EFMQ provides an MQTT pub/sub style abstraction for Ethernet Frame messaging.

GoDoc

EFMQ is like MQTT for your Local Area Network. Unlike MQTT no remote or local broker is required, message traffic is effectively broadcast peer-to-peer. With EFMQ, messages never leave your network.

Messaging can be two-way. Each node can operate as either a publisher or subscriber, or both.

This package leans heavily on @mdlayher's raw and ethernet packages, which do almost all the heavy lifting.

Usage

Basic publisher and subscriber examples are provided below. Nodes can publish and subscribe to multiple topics.

The API follows a typical MQTT client API loosely.

// Create connection
mq, _ := efmq.NewEFMQ(networkInterface string)

// Publish
mq.Publish(topic string, payload string)

// Subscribe
mq.Subscribe(topic string)

// Unsubscribe
mq.Unsubscribe(topic string)

// List subscriptions
mq.Subscriptions()

// Start listening
mq.Listen()

// Message channel
mq.Message

// Message 
Message struct {
	Topic string
	Payload string
}

Publisher example

The code below will publish data to the fermenter topic every second. en1 is the network interface on Mac (my Mac at least). On a Raspberry Pi it might be wlan0. Use netstat -i to discover.

mq, err := efmq.NewEFMQ("en1") 
if err != nil {
	log.Fatal(err)
}
t := time.NewTicker(1 * time.Second)
for range t.C {
	if err := mq.Publish("fermenter", "20.5"); err != nil {
		log.Fatalln(err)
	}
}

Subscriber example

The code below sets up a subcription to the fermenter topic and then listens for messages. Messages are received on a channel.

mq, err := efmq.NewEFMQ("wlan0")
if err != nil {
	log.Fatal(err)
}
mq.Subscribe("fermenter")
mq.Listen()
for msg := range mq.Message {
	fmt.Println("topic:", msg.Topic)
	fmt.Println("message:", msg.Payload)
}

Todo

  • Better test coverage
  • Check message does not exceed frame byte data limit (1500 bytes?)

efmq's People

Stargazers

Radu Topala avatar  avatar Sem avatar bradley avatar Serge Simard avatar Bogdan U avatar Rafael Escobar avatar Nathanaelle avatar Felipe Oliveira avatar Matt Layher avatar

Watchers

James Cloos avatar  avatar

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.