Skip to content

Example server type assertion doesn't work, causes example to not work #47

@svansteelandt

Description

@svansteelandt

In example/obsserver/obsserver.go, line 42-45:

if value, ok := m.Option(coap.Observe).([]uint8); ok &&
					len(value) >= 1 && value[0] == 1 {
					go periodicTransmitter(l, a, m)
}

The type assertion gives a false for okay and a wrong value. This causes the if-clause to fail, and so the function periodicTransmitter is never called. I changed the code like this to get it to work:

obss := fmt.Sprint(m.Option(coap.Observe))
value, err := strconv.Atoi(obss)
if err != nil {
	log.Fatalf("Could not convert observe value to int", err)
}
if value == 1 {
	go periodicTransmitter(l, a, m)
}

with imports of fmt and strconv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions