Пример #1
0
func main() {

	fmt.Println("Data packets")

	A5_02_05pattern := []byte{85, 0, 10, 2, 10, 155, 34, 4, 0, 87, 200, 0, 0, 76, 8, 93, 1, 50, 139}
	A5_04_01pattern := []byte{85, 0, 10, 2, 10, 155, 34, 4, 1, 121, 77, 0, 166, 192, 10, 11, 1, 45, 214}

	// A5_02_05 Temperture
	err, c, e := enocean.NewESPData(A5_02_05pattern)
	if err != nil {
		fmt.Printf("ERROR: %v, parse failed on %v. consumed %v", err, A5_02_05pattern, c)
	}

	temp := (255 - int(e.PayloadData[2])) * 40.0 / 255
	fmt.Printf("%v : temperature %v\n", e, temp)

	// A5_04_01 Humidity/Temperture
	err, c, e2 := enocean.NewESPData(A5_04_01pattern)
	if err != nil {
		fmt.Printf("ERROR: %v, parse failed on %v. consumed %v", err, A5_04_01pattern, c)
	}

	humid := int(e2.PayloadData[1]) * 100.0 / 250
	temp2 := int(e2.PayloadData[2]) * 40.0 / 250

	fmt.Printf("%v : humidity: %v, temperature: %v\n", e2, humid, temp2)
}
Пример #2
0
func TestVariousRORGTeachInPacketAccept(t *testing.T) {
	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},
		{85, 0, 10, 2, 10, 155, 34, 4, 0, 79, 66, 0, 0, 62, 8, 78, 1, 55, 144, 10}, // not TeachIn case
	}

	validity := []bool{
		true,
		true,
		false,
	}

	for i, v := range patterns {
		err, consumedBytes, e := enocean.NewESPData(v)
		if err != nil {
			t.Errorf("ERROR: %v, parse failed on %v. consumed %v, ", err, v, consumedBytes)
		}
		if !validity[i] {
			if e.TeachIn == true {
				t.Errorf("ERROR: %v, not teach in data is flagged as teach-in at %v", e, i)
			} else {
				continue
			}
		}
		if (e.TeachIn == false) ||
			(e.RORG == 0) ||
			(e.FUNC == 0) ||
			(e.TYPE == 0) ||
			(e.ManufacturerId == 0) {
			t.Errorf("ERROR: %v, teach in data extraction failed on %v. consumed %v, ", e, v, consumedBytes)
		}
	}
}
Пример #3
0
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)
	}
}
Пример #4
0
func TestRSSIvalue(t *testing.T) {
	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 {
			t.Errorf("ERROR: %v, parse failed on %v. consumed %v, ", err, v, consumedBytes)
		}
		if e.RSSI != v[len(v)-2] {
			t.Errorf("ERROR: RSSI data %v is differ from %v on %v. consumed %v, ", e.RSSI, v[len(v)-2], v, consumedBytes)
		}
	}
}
Пример #5
0
func TestVariousPacketAccept(t *testing.T) {
	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, 0, 87, 200, 8, 40, 11, 128, 131, 1, 55, 144},
		{85, 0, 10, 2, 10, 155, 34, 4, 0, 87, 200, 0, 0, 80, 8, 246, 1, 41, 202},
		{85, 0, 10, 2, 10, 155, 34, 4, 0, 87, 200, 0, 0, 80, 8, 246, 1, 55, 144},
		{85, 0, 12, 2, 10, 230, 98, 0, 0, 4, 1, 121, 77, 16, 8, 11, 128, 48, 1, 41, 202},
		{85, 0, 10, 2, 10, 155, 34, 4, 1, 121, 77, 0, 166, 192, 10, 11, 1, 45, 214},
		{85, 0, 10, 2, 10, 155, 34, 4, 1, 121, 77, 0, 197, 205, 10, 154, 1, 45, 214},
		{85, 0, 10, 2, 10, 155, 34, 4, 1, 121, 77, 0, 180, 176, 10, 221, 1, 43, 196},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 132, 242, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 136, 214, 1, 73, 237},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 61, 166},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 132, 242, 1, 46, 223},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 45, 214},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 136, 214, 1, 42, 195},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 136, 214, 1, 42, 195},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 136, 214, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 136, 214, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 132, 242, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 132, 242, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 132, 242, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 132, 242, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 0, 43, 146, 87, 0, 103, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 4, 0, 62, 127, 0, 24, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 4, 0, 62, 127, 0, 24, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 4, 0, 62, 127, 128, 145, 1, 41, 202},
		{85, 0, 7, 2, 10, 10, 32, 4, 0, 62, 127, 128, 145, 1, 41, 202},
	}

	for _, v := range patterns {
		err, consumedBytes, _ := enocean.NewESPData(v)
		if err != nil {
			t.Errorf("ERROR: %v, parse failed on %v. consumed %v, ", err, v, consumedBytes)
		}
	}
}
Пример #6
0
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
}