PaulS:
No Strings used.
Paul, I REALLY appreciate your time. Your code gives me
expected constructor, destructor, or type conversion before '(' token
and the IDE highlights the final
strcat(subscription, slash);
Here is the complete code (that works with String, but will not work with char)
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <stdlib.h>
#define ONE_WIRE_BUS 11
int resolution = 10; //.5 celcius
#define DEVICE "OfficeArduino"
#define DEVICEHELLO "OfficeArduino Connected"
//String campus = "campus";
//String building = "building";
//String room = "office";
//String subscription = campus+'/'+building+'/'+room+'/'+'#';
String test;
char *campus = "mycampus";
char *building = "mybuilding";
char *room = "office";
char *slash = "/";
char subscription[80];
strcpy(subscription, campus);
strcat(subscription, slash);
strcat(subscription, building);
strcat(subscription, slash);
strcat(subscription, room);
strcat(subscription, slash);
float setpoint = 45.00;
float actual = 44.44;
int state = 0;
int request = 0;
long lastMsg = 0;
float temp = 0;
char *cstring;
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 221);
IPAddress server(192, 168, 0, 222);
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress office = { 0x28, 0xFF, 0x46, 0x82, 0x58, 0x16, 0x04, 0x9A };
void callback(char* topic, byte* payload, unsigned int length) {
for (int i=0;i<length;i++) {
payload[length] = '\0';
cstring = (char *) payload;
}
Serial.println(topic);
Serial.println(cstring);
setpoint = atof(cstring);
Serial.println("The setpoint is...");
}
EthernetClient ethClient;
PubSubClient client(ethClient);
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect(DEVICE)) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic",DEVICEHELLO);
// ... and resubscribe
client.subscribe(subscription.c_str());
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
// disable SD card if one in the slot
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Serial.begin(57600);
sensors.begin();
sensors.setResolution(office, resolution);
client.setServer(server, 1883);
client.setCallback(callback);
Ethernet.begin(mac, ip);
// Allow the hardware to sort itself out
delay(1500);
}
void loop()
{
if (!client.connected()) {
reconnect();
}
client.loop();
long now = millis();
if (now - lastMsg > 60000) {
lastMsg = now;
sensors.requestTemperatures(); // Send the command to get temperatures
temp = sensors.getTempF(office);
Serial.println(temp);
if (temp == -127.00) {
Serial.println("error");
} else {
//client.publish("mytopic", String(temp).c_str(),TRUE);
client.subscribe(subscription);
}
}
}