Giter Site home page Giter Site logo

simple-messaging-mqtt's Introduction

Simple Messaging MQTT (SMM)

A tiny library for MQTT android client

About

  • This library based on Paho from Eclipse
  • Simple implementation in your activity or service
  • Simple implementation with any MQTT Cloud
  • Support java and kotlin

Setup MQTT Cloud

Use any MQTT Cloud like cloudmqtt.com or cloudamqp.com or whatever.
Go to configuration, copy your server, port, username and password. Just like that!

Download

Download

implementation "com.utsman.messaging:smm:${latest_version}"

// for androidx support, just add
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

Let's code!

Setup server

In AndroidManifest.xml, add the following element as a child of the <application> element, by inserting it just before the closing </application> tag.

<meta-data android:name="com.utsman.smm.SERVER"
           android:value="tcp://server_url:port"/>

<meta-data android:name="com.utsman.smm.USERNAME"
           android:value="username"/>

<meta-data android:name="com.utsman.smm.PASSWORD" 
           android:value="password"/>

<meta-data android:name="com.utsman.smm.CLIENT_ID"
           android:value="client_id"/>

Setup receiver in activity or fragment or service

Smm.subscribe(context, "topic") { senderId, data ->
    // message arrived with JSONObject data
    val name = data.getString("name")
}

Setup in button for publish data

// setup your JSONObject data
val data = JSONObject()
data.putString("name", "Sarah")

// publish your data
Smm.publish(context, "topic", data)


Copyright 2019 Muhammad Utsman

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

simple-messaging-mqtt's People

Contributors

kucingapes avatar

Watchers

James Cloos avatar Muhammad Utsman 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.