Removed Sevice field - we do not need it for now
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
parent
1d74046154
commit
d1c44a5413
|
@ -64,7 +64,7 @@ func (mqc *MqttConn) MqttSub() {
|
|||
// Subscribe to all channels of all the devices and request messages to be delivered
|
||||
// at a maximum qos of zero, wait for the receipt to confirm the subscription
|
||||
// Topic is in the form:
|
||||
// mainflux/<service>/<channel_id>
|
||||
// mainflux/<channel_id>
|
||||
if token := mqc.Client.Subscribe("mainflux/#", 0, nil); token.Wait() && token.Error() != nil {
|
||||
fmt.Println(token.Error())
|
||||
}
|
||||
|
|
|
@ -252,35 +252,10 @@ func UpdateChannel(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
id := bone.GetValue(r, "channel_id")
|
||||
|
||||
// Get the channels "device_id"
|
||||
c := models.Channel{}
|
||||
if err := Db.C("channels").Find(bson.M{"id": id}).
|
||||
Select(bson.M{"device": 1}).
|
||||
One(&c); err != nil {
|
||||
log.Print(err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
str := `{"response": "cannot find channel's device", "id": "` + id + `"}`
|
||||
io.WriteString(w, str)
|
||||
return
|
||||
}
|
||||
|
||||
// Get device to check service it belongs to
|
||||
d := models.Device{}
|
||||
if err := Db.C("devices").Find(bson.M{"id": c.Device}).
|
||||
Select(bson.M{"service": 1}).
|
||||
One(&d); err != nil {
|
||||
log.Print(err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
str := `{"response": "device not found", "id": "` + id + `"}`
|
||||
io.WriteString(w, str)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Publish the channel update.
|
||||
// This will be catched by the MQTT main client (subscribed to all channel topics)
|
||||
// and then written in the DB in the MQTT handler
|
||||
token := clients.MqttClient.Publish("mainflux/" + d.Service + "/" + id, 0, false, string(data))
|
||||
token := clients.MqttClient.Publish("mainflux/" + id, 0, false, string(data))
|
||||
token.Wait()
|
||||
|
||||
// Wait on status from MQTT handler (which executes DB write)
|
||||
|
|
|
@ -70,7 +70,7 @@ func CreateDevice(w http.ResponseWriter, r *http.Request) {
|
|||
defer Db.Close()
|
||||
|
||||
// Set up defaults and pick up new values from user-provided JSON
|
||||
d := models.Device{Name: "Some Name", Service: "main", Online: false}
|
||||
d := models.Device{Name: "Some Name", Online: false}
|
||||
if err := json.Unmarshal(data, &d); err != nil {
|
||||
println("Cannot decode!")
|
||||
log.Print(err.Error())
|
||||
|
|
|
@ -15,10 +15,6 @@ type (
|
|||
|
||||
Description string `json:"description"`
|
||||
|
||||
// Service (gateway) to which this device belongs to
|
||||
// If device connects directly to Mainflux, use `main` (default)
|
||||
Service string `json:"service"`
|
||||
|
||||
Online bool `json:"online"`
|
||||
ConnectedAt string `json:"connected_at"`
|
||||
DisonnectedAt string `json:"disconnected_at"`
|
||||
|
|
Loading…
Reference in New Issue