func main() { fmt.Println("Teach In packets") patterns := [][]byte{ {85, 0, 12, 2, 10, 230, 98, 0, 0, 4, 0, 87, 200, 8, 40, 11, 128, 131, 1, 53, 158}, {85, 0, 12, 2, 10, 230, 98, 0, 0, 4, 1, 121, 77, 16, 8, 11, 128, 48, 1, 41, 202}, } for _, v := range patterns { err, consumedBytes, e := enocean.NewESPData(v) if err != nil { fmt.Printf("ERROR: %v, parse failed on %v. consumed %v, ", err, v, consumedBytes) } if (e.TeachIn == false) || (e.RORG == 0) || (e.FUNC == 0) || (e.TYPE == 0) || (e.ManufacturerId == 0) { fmt.Printf("ERROR: %v, teach in data extraction failed on %v. consumed %v, ", e, v, consumedBytes) return } fmt.Printf("\nRaw data: %v\n", e) err, m := enocean.GetManufacturerName(e.ManufacturerId) if err != nil { fmt.Printf("ERROR: %v, manufacturerID is wrong", e.ManufacturerId) return } fmt.Printf("RORG: %x, FUNC: %v, TYPE: %v ManufacturerId: %v\n", e.RORG, e.FUNC, e.TYPE, m) } }
func OnMessageReceived(client MQTT.Client, message MQTT.Message) { buf := message.Payload() log.Infof("topic:%s / msg:%s", message.Topic(), buf) // analyze temperture data err, c, e := enocean.NewESPData(buf) if err != nil { log.Errorf("ERROR: %v, parse failed on $v, cosumed %v", err, buf, c) } temp := (255 - int(e.PayloadData[2])) * 40.0 / 255 err, m := enocean.GetManufacturerName(e.ManufacturerId) if err != nil { log.Errorf("ERROR: %v, manufacturer ID is wrong", e.ManufacturerId) } msg := fmt.Sprintf("{\"RawData\": \"%v\", \"TeachIn\": %v, \"manufactuererId\": \"%v\", \"temperature\": %v}", e, e.TeachIn, m, temp) fmt.Println(msg) msgPipe <- msg }
func TestManufacturerIdRange(t *testing.T) { for _, id := range []int{ int(enocean.MANUFACTURER_RESERVED), int(enocean.PEHA), int(enocean.THERMOKON), int(enocean.SERVODAN), int(enocean.ECHOFLEX_SOLUTIONS), int(enocean.OMNIO_AG), int(enocean.HARDMEIER_ELECTRONICS), int(enocean.REGULVAR_INC), int(enocean.AD_HOC_ELECTRONICS), int(enocean.DISTECH_CONTROLS), int(enocean.KIEBACK_AND_PETER), int(enocean.ENOCEAN_GMBH), int(enocean.PROBARE), int(enocean.ELTAKO), int(enocean.LEVITON), int(enocean.HONEYWELL), int(enocean.SPARTAN_PERIPHERAL_DEVICES), int(enocean.SIEMENS), int(enocean.T_MAC), int(enocean.RELIABLE_CONTROLS_CORPORATION), int(enocean.ELSNER_ELEKTRONIK_GMBH), int(enocean.DIEHL_CONTROLS), int(enocean.BSC_COMPUTER), int(enocean.S_AND_S_REGELTECHNIK_GMBH), int(enocean.MASCO_CORPORATION), int(enocean.INTESIS_SOFTWARE_SL), int(enocean.VIESSMANN), int(enocean.LUTUO_TECHNOLOGY), int(enocean.SCHNEIDER_ELECTRIC), int(enocean.SAUTER), int(enocean.BOOT_UP), int(enocean.OSRAM_SYLVANIA), int(enocean.UNOTECH), int(enocean.DELTA_CONTROLS_INC), int(enocean.UNITRONIC_AG), int(enocean.NANOSENSE), int(enocean.THE_S4_GROUP), int(enocean.MSR_SOLUTIONS), int(enocean.GE), int(enocean.MAICO), int(enocean.RUSKIN_COMPANY), int(enocean.MAGNUM_ENERGY_SOLUTIONS), int(enocean.KMC_CONTROLS), int(enocean.ECOLOGIX_CONTROLS), int(enocean.TRIO_2_SYS), int(enocean.AFRISO_EURO_INDEX), int(enocean.NEC_ACCESSTECHNICA_LTD), int(enocean.ITEC_CORPORATION), int(enocean.SIMICX_CO_LTD), int(enocean.EUROTRONIC_TECHNOLOGY_GMBH), int(enocean.ART_JAPAN_CO_LTD), int(enocean.TIANSU_AUTOMATION_CONTROL_SYSTE_CO_LTD), int(enocean.GRUPPO_GIORDANO_IDEA_SPA), int(enocean.ALPHAEOS_AG), int(enocean.TAG_TECHNOLOGIES), int(enocean.CLOUD_BUILDINGS_LTD), int(enocean.GIGA_CONCEPT), int(enocean.SENSORTEC), int(enocean.JAEGER_DIREKT), int(enocean.AIR_SYSTEM_COMPONENTS_INC), int(enocean.MULTI_USER_MANUFACTURER), } { err, val := enocean.GetManufacturerName(id) if err != nil { t.Errorf("ID: %v is errored to get its name", id) } if "" == val { t.Errorf("ID: %v does not have its name", id) } } }