boolean ActuatorProxy::write (char* what, char*& reply) { boolean ret; char buf[SZ]; buf[0] = '\0'; strncat_P (buf, PSTR ("WRI "), SZ); strncat (buf, name, SZ); strncat_P (buf, PSTR (" "), SZ); strncat (buf, what, SZ); strncat_P (buf, PSTR ("\n"), SZ); ret = srvpx -> sendcmd (buf, reply); return ret; }
/* NB expects name to be a pointer to a string in progmem */ static int32_t read_probe(const char *name) { uint8_t addr[8]; const struct reg *r; struct storage s; char regname[9]; strncpy_P(regname,name,9); strncat_P(regname,PSTR("/id"),9); r=reg_by_name(regname); s=reg_storage(r); eeprom_read_block(addr,(void *)s.loc.eeprom.start,8); return owb_read_temp(addr); }
void bsbport_poll_cb(void) { BSBDEBUG("MQTT Poll"); for (uint8_t i = 0; i < BSBPORT_MESSAGE_BUFFER_LEN; i++) { if (bsbport_msg_buffer.msg[i].mqtt_new) { uint8_t len; uint8_t topic_len; char buf[DATA_LENGTH]; char topic[TOPIC_LENGTH]; bsbport_msg_buffer.msg[i].mqtt_new = 0; // Topic topic_len = snprintf_P(topic, TOPIC_LENGTH, publish_topic_format, LO4(bsbport_msg_buffer.msg[i].src), bsbport_msg_buffer.msg[i].p.data.p1, bsbport_msg_buffer.msg[i].p.data.p2, bsbport_msg_buffer.msg[i].p.data.p3, bsbport_msg_buffer.msg[i].p.data.p4); // RAW strncat_P(topic, PSTR("RAW"), TOPIC_LENGTH - topic_len - 1); len = snprintf_P(buf, DATA_LENGTH, PSTR("%u"), bsbport_msg_buffer.msg[i].value); mqtt_construct_publish_packet(topic, buf, len, BSBPORT_MQTT_RETAIN); BSBDEBUG("%s=%s", topic, buf); // STA topic[topic_len]=0; strncat_P(topic, PSTR("STA"), TOPIC_LENGTH - topic_len - 1); len = snprintf_P(buf, DATA_LENGTH, PSTR("%u"), HI8(bsbport_msg_buffer.msg[i].value)); mqtt_construct_publish_packet(topic, buf, len, BSBPORT_MQTT_RETAIN); BSBDEBUG("%s=%s", topic, buf); // TMP topic[topic_len]=0; strncat_P(topic, PSTR("TMP"), TOPIC_LENGTH - topic_len - 1); len = itoa_fixedpoint(((int32_t) bsbport_msg_buffer.msg[i].value * 100) / 64, 2, buf, DATA_LENGTH); mqtt_construct_publish_packet(topic, buf, len, BSBPORT_MQTT_RETAIN); BSBDEBUG("%s=%s", topic, buf); // FP1 topic[topic_len]=0; strncat_P(topic, PSTR("FP1"), TOPIC_LENGTH - topic_len - 1); len = itoa_fixedpoint(bsbport_msg_buffer.msg[i].value, 1, buf, DATA_LENGTH); mqtt_construct_publish_packet(topic, buf, len, BSBPORT_MQTT_RETAIN); BSBDEBUG("%s=%s", topic, buf); // FP5 topic[topic_len]=0; strncat_P(topic, PSTR("FP5"), TOPIC_LENGTH - topic_len - 1); len = itoa_fixedpoint(bsbport_msg_buffer.msg[i].value * 10 / 2, 1, buf, DATA_LENGTH); mqtt_construct_publish_packet(topic, buf, len, BSBPORT_MQTT_RETAIN); BSBDEBUG("%s=%s", topic, buf); } } }