/* the radian_trx SW shall not be distributed nor used for commercial product*/ /* it is exposed just to demonstrate CC1101 capability to reader water meter indexes */ #ifndef METER_YEAR #define METER_YEAR 16 #endif #ifndef METER_SERIAL #define METER_SERIAL 123456 #endif #ifndef MQTT_HOST #define MQTT_HOST "localhost" #endif #ifndef MQTT_PORT #define MQTT_PORT 1883 #endif #ifndef MQTT_USER #define MQTT_USER "homeassistant" #endif #ifndef MQTT_PASS #define MQTT_PASS "PASS" #endif #define MQTT_KEEP_ALIVE 60 #define MQTT_MSG_MAX_SIZE 512 #include #include #include #include #include "everblu_meters.h" #include "cc1101.c" void IO_init(void) { wiringPiSetup(); pinMode (GDO2, INPUT); pinMode (GDO0, INPUT); cc1101_init(); } void my_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message) { if(message->payloadlen){ printf("%s %s", message->topic, (char *)message->payload); }else{ //printf("%s (null)\n", message->topic); } fflush(stdout); } void my_connect_callback(struct mosquitto *mosq, void *userdata, int result) { if(!result){ /* Subscribe to broker information topics on successful connect. */ mosquitto_subscribe(mosq, NULL, "WaterUsage ", 2); struct tmeter_data meter_data = { .liters = -1, .battery_left = -1, .reads_counter = -1, .time_start = -1, .time_end = -1, }; char mqtt_topic[64]; char buff[MQTT_MSG_MAX_SIZE]; char meter_id[12]; sprintf(meter_id, "%i_%i", METER_YEAR, METER_SERIAL); IO_init(); meter_data = get_meter_data(); cc1101_reset(); sprintf(buff, "%d", meter_data.liters); sprintf(mqtt_topic, "homeassistant/sensor/cyblemeter_%s/state", meter_id); printf("Liters: %i\n", meter_data.liters); if(mosquitto_publish(mosq, NULL, mqtt_topic, strlen(buff),buff,1,true) != MOSQ_ERR_SUCCESS) fprintf(stderr, "ERROR: could not publish message"); }else{ fprintf(stderr, "Connect failed\n"); } } void my_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos) { int i; printf("Subscribed (mid: %d): %d", mid, granted_qos[0]); for(i=1; i