<commit_before>package main

import "fmt"

func main() {
	fmt.Println("hello mongo")
}<commit_msg>simple mqtt client with mongo<commit_after>package main

import (
	"fmt"
	"os"
	"runtime"
	"time"

	"labix.org/v2/mgo"

	MQTT "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
)

type Sensor struct {
	holder []byte
	id     byte
	prefix byte
	code   byte
}

var session = new(mgo.Session)
var collection *mgo.Collection

func mgoSessionFinalizer(session *mgo.Session) {
	session.Close()
}

func init() {
	runtime.SetFinalizer(session, mgoSessionFinalizer)
	var err error
	//TODO: obtain MongoDB details from configuration
	session, err = mgo.Dial("db.skydome.io:27017")
	if err != nil {
		panic(err)
	}

	session.SetMode(mgo.Monotonic, true)
	collection = session.DB("sensors").C("raw")
}

var f MQTT.MessageHandler = func(client *MQTT.MqttClient, msg MQTT.Message) {
	//fmt.Printf("TOPIC: %s\n", msg.Topic())
	fmt.Println("Size of array : ", len(msg.Payload()))
	fmt.Println("MSG: ", msg.Payload())

	sensor := Sensor{msg.Payload()[:6], msg.Payload()[6], msg.Payload()[7], msg.Payload()[8]}
	fmt.Println("sensor : ", sensor)
	collection.Insert(sensor)
}

func main() {
	opts := MQTT.NewClientOptions().SetBroker("tcp://172.16.58.3:1883").SetClientId("trivial")
	opts.SetTraceLevel(MQTT.Off)
	opts.SetDefaultPublishHandler(f)

	c := MQTT.NewClient(opts)
	_, err := c.Start()
	if err != nil {
		panic(err)
	}

	filter, _ := MQTT.NewTopicFilter("skydome", 0)
	if receipt, err := c.StartSubscription(nil, filter); err != nil {
		fmt.Println(err)
		os.Exit(1)
	} else {
		<-receipt
	}

	for {
		time.Sleep(1 * time.Second)
	}
}
{'fraction_non_alphanumeric': 0.1701346389228886, 'fraction_numerical': 0.015299877600979192, 'mean_word_length': 4.360655737704918, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '384332', 'n_tokens_mistral': 673, 'n_tokens_neox': 639, 'n_words': 122}