Skip to content

Instantly share code, notes, and snippets.

@ralight
ralight / printer.py
Created October 31, 2012 19:07
Print incoming MQTT messages with a maximum width of 32 characters.
#!/usr/bin/python
import mosquitto
import textwrap
def on_message(mosq, obj, msg):
for s in textwrap.wrap(msg.payload, width=32):
print(s)
mqttc = mosquitto.Mosquitto()
@ralight
ralight / retained.py
Last active December 14, 2015 07:08
Retained message test, with QoS=2.
#!/usr/bin/python
import mosquitto
import time
pub_sent = False
def pub_on_connect(mosq, obj, rc):
mosq.publish("/A/B", "message one", 2, True)
mosq.publish("/A/B", "message two", 2, True)
@ralight
ralight / utf8.py
Created March 17, 2013 16:56
Testing Python and mosquitto.py utf8 encoding.
#!/usr/bin/python
# vim: set fileencoding=utf8 :
import mosquitto
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def on_message(mosq, obj, msg):
print(msg.topic + " : " + msg.payload)
@ralight
ralight / multi.py
Last active December 15, 2015 02:39
Create 1000 mqtt clients (in 1000 threads) to test broker connections.
#!/usr/bin/python
import mosquitto
import time
def on_connect(mosq, obj, rc):
print("Connected: "+mosq._client_id)
def on_disconnect(mosq, obj, rc):
print("Disconnected: "+mosq._client_id + " ("+str(rc)+")")
import getopt
import mosquitto
import sys
final_mid = 0
def on_connect(mosq, userdata, rc):
if userdata == True:
print("rc: "+str(rc))
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <mosquitto.h>
#define MAX 100000
@ralight
ralight / compiling
Created January 9, 2014 11:30
Test libmosquitto SSL against howsmyssl.com
cd mosquitto/lib
cp somewhere/hows.c .
gcc hows.c net_mosq.c logging_mosq.c memory_mosq.c messages_mosq.c mosquitto.c read_handle.c read_handle_client.c read_handle_shared.c send_mosq.c send_client_mosq.c time_mosq.c tls_mosq.c util_mosq.c will_mosq.c -I. -I.. -DWITH_TLS -lrt -lssl -lcrypto -o hows
./hows

Keybase proof

I hereby claim:

  • I am ralight on github.
  • I am ralight (https://keybase.io/ralight) on keybase.
  • I have a public key whose fingerprint is A0D6 EEA1 DCAE 49A6 35A3 B2F0 779B 22DF B3E7 17B7

To claim this, I am signing this object:

@ralight
ralight / consumer.c
Last active September 30, 2015 11:38
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <fcntl.h>
#define BUF_SIZE 10000
#include <stdio.h>
#include <stdlib.h>
#define COUNT 100000
#define BLOCKSIZE 1000
int main(int argc, char *argv[])
{
char **ptr;