I am using a ciseco xinoRF to control a pc fan using a dallas temp sensor.
I have been having problems with the code in that it does not send the Starting Message or temp.
When I remove the code for the fan it works ok but as soon as I put it back in it stops.
I am getting a bit frustrated and think I must be missing something fundamental.
Thank you
// Do not remove the include below
#include "LLAPav.h"
#include <LLAPSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//The setup function is called once at startup of the sketch
/*LLAP AV
* Aim to control fan in av cabenet depending on temp
* Upload to LLAP
* Enable manual overide Possiible
*/
#define ONE_WIRE_BUS 9 //Temp input pin
#define TEMPERATURE_PRECISION 9
#define FanOutputPin 3 //Fan Output Pin
#define DEVICEID "AV" // this is the LLAP device ID
// Setup Temp Sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
unsigned long lastmillis = 0;
unsigned long llapmillis = 0;
char TempString[10];
char RPMString[10];
double Input = 0;
double minTemp = 20;
// inputs
uint8_t inputs[] = {2,3,4,7,10,12,254};
String msg; // storage for incoming message
String reply; // storage for reply
void setup()
{
//Start LLAP
Serial.begin(115200);
LLAP.init(DEVICEID);
pinMode(8,OUTPUT); // switch on the radio
digitalWrite(8,HIGH);
pinMode(4,OUTPUT); // switch on the radio
digitalWrite(4,LOW); // ensure the radio is not sleeping
delay(400); // allow the radio to startup
byte i=0;
while (inputs[i] != 254) {pinMode(inputs[i],INPUT); digitalWrite(inputs[i++],HIGH);}
i=0;
String permittedChars = "-#@?\\*ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//Temp setup
sensors.begin();
sensors.requestTemperatures();
Input = sensors.getTempCByIndex(0); //Set Input to Current Temperature
//Setup Pins
pinMode(FanOutputPin, OUTPUT);
LLAP.sendMessage(F("STARTED")); // send the usual "started message
digitalWrite(FanOutputPin, HIGH);
}
void loop()
{
//llap recieve
if (LLAP.bMsgReceived) // got a message?
{
msg = LLAP.sMessage;
LLAP.bMsgReceived = false;
reply = msg;
if (msg.compareTo("HELLO----") == 0)
{
; // just echo the message back
}
else if (msg.startsWith("SETT"))
{
msg = msg.substring(5);
int value = msg.toInt();
minTemp = value;
reply = "TempSet-";
}
}
//Read Temp
if(millis() - lastmillis == 10000){
sensors.requestTemperatures();
Input=sensors.getTempCByIndex(0);
if(Input<= minTemp){
digitalWrite(FanOutputPin, HIGH);
}
else{
digitalWrite(FanOutputPin, LOW);
}
lastmillis = millis();
}
//Need to add LLAP output
if(millis() - llapmillis == 60000){
sensors.requestTemperatures();
Input=sensors.getTempCByIndex(0);
if (isnan(Input)){
LLAP.sendMessage(F("ERROR"));
} else {
dtostrf(Input,5,2,TempString);
String ST;
ST = "T" + String(TempString);
LLAP.sendMessage(ST);
}
llapmillis = millis();
}
}