Im looking for some help/adivse as to while i keep getting this error message “a function-definition is not allowed here before ‘{’ token”.
Its the “{” right below the void setup. iv tried variuos things with no luck.
Could anyone point me in the right direction.
Thanks in advance.
Adam.
#include <SimpleTimer.h>
#include <OneWire.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
SimpleTimer timer;
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You’ll need:
- Blynk App (download from AppStore or Google Play)
- Arduino Mega 2560 board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <BlynkSimpleEthernet.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
OneWire ds(48); // on pin 48 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.
int adr;
float s1;
float s2;
float s3;
float s4;
float s5;
float s6;
float s7;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "d27bf6f0a098498a81a5c65dab79b851";
#define W5100_CS 10
#define SDCARD_CS 4
float SetPoint = 20; //temperature set-point
float Differential = 2; //temperature control differential
int Relay1 = 22;
int Relay2 = 23;
int Relay3 = 24;
int Relay4 = 25;
int Heater1 = 50;
int Heater2 = 51;
int Cooling = 28;
float temperature = NAN;
float lowAlarm = NAN;
float highAlarm = NAN;
int int_probe_type = 0; //convert char to int to use Switch case
int button_pressed = 0; //virtual button variable
// temperature control
BLYNK_WRITE(V11){
//reads the setppoint
SetPoint = param.asFloat();
}
BLYNK_WRITE(V12){
//reads the differential
Differential = param.asFloat();
}
BLYNK_WRITE(V32){
//reads low alarm
lowAlarm = param.asFloat();
}
BLYNK_WRITE(V33){
//reads high alarm
highAlarm = param.asFloat();
}
BLYNK_WRITE(V40){
//receive button state from Blynk App
button_pressed = param.asInt();
}
void HandleRLYControl(){
//if sensor not sending temperature turn relay OFF for safety
if (isnan(temperature) && Heater1 HIGH) {
Heater1 = false;
Heater2 = false;
digitalWrite(Heater1, LOW);
digitalWrite(Heater2, LOW);
}
else if (!isnan(temperature))
{
if(Heater1){
if (temperature < (SetPoint - Differential) && !Heater1 HIGH) {
digitalWrite(Heater1, HIGH);
digitalWrite(Heater2, HIGH);
Heater1 = true;
Heater2 = true;
}
else if (temperature >= SetPoint && Heater1 HIGH) {
digitalWrite(Heater1, LOW);
digitalWrite(Heater2, LOW);
Heater1 = false;
Heater2 = false;
}
}
if (Cooling){
if (temperature > (SetPoint + Differential) && !Cooling HIGH) {
digitalWrite(Cooling, HIGH);
Cooling = true;
}
else if (temperature <= SetPoint && Heater1 HIGH,Heater2 HIGH ) {
digitalWrite(Heater1, LOW);
digitalWrite(Heater2, LOW);
Heater1 = false;
Heater2 = false;
}
}
}
void setup()
{
//Prevent relay trigger on bootup
pinMode(22, INPUT_PULLUP);
//Define the relay pins
pinMode(22, OUTPUT);
//Prevent relay trigger on bootup
pinMode(23, INPUT_PULLUP);
//Define the relay pins
pinMode(23, OUTPUT);
//Prevent relay trigger on bootup
pinMode(24, INPUT_PULLUP);
//Define the relay pins
pinMode(24, OUTPUT);
//Prevent relay trigger on bootup
pinMode(25, INPUT_PULLUP);
//Define the relay pins
pinMode(25, OUTPUT);
//Prevent relay trigger on bootup
pinMode(26, INPUT_PULLUP);
//Define the relay pins
pinMode(26, OUTPUT);
//Prevent relay trigger on bootup
pinMode(27, INPUT_PULLUP);
//Define the relay pins
pinMode(27, OUTPUT);
//Prevent relay trigger on bootup
pinMode(28, INPUT_PULLUP);
//Define the relay pins
pinMode(28, OUTPUT);
//Prevent relay trigger on bootup
pinMode(29, INPUT_PULLUP);
//Define the relay pins
pinMode(29, OUTPUT);
//Prevent relay trigger on bootup
pinMode(30, INPUT_PULLUP);
//Define the relay pins
pinMode(30, OUTPUT);
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
Blynk.begin(auth);
// You can also specify server:
//Blynk.begin(auth, "blynk-cloud.com", 80);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8080);
// relay control- delay - turning off multiple relays with the return pump
}
}
void TurnRelaysOn()
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
}
BLYNK_WRITE(V1) // Set to your Buttons vPin
int pinValue = param.asInt(); // Get State of Virtual Button, Return pump
if (pinValue == 0); // if button off
digitalWrite(Relay2, LOW); // turn skimmer off
digitalWrite(Relay2, LOW); // turn Reactor off
if (pinValue == 1); // if button on
timer.setTimeout(3000, TurnRelaysOn);}
}
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
// Debug console
Serial.begin(9600);
}
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
// Serial.print("ROM =");
for( i = 0; i < 8; i++) { //we need to drop 8 bytes of data
}
adr = (addr[7]);
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes to drop off
data[i] = ds.read();
}
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
if(adr == 239) { //replace ??? with value of sensor number 1
s1 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr ==2 ) { //replace ??? with value of sensor number 2
s2 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
Serial.print(" Sensor 1 = ");
Serial.print(s1);
Serial.print(" Sensor 2 = ");
Serial.print(s2);
Serial.print(" Sensor 3 = ");
Serial.print(s3);
Serial.print(" Sensor 4 = ");
Serial.print(s4);
Serial.print(" Sensor 5 = ");
Serial.print(s5);
Serial.print(" Sensor 6 = ");
Serial.print(s6);
Serial.print(" Sensor 7 = "); //add or delete if you need more or less
Serial.print(s7);
Blynk.virtualWrite(V5, s1);
Blynk.virtualWrite(V6, s2);
Blynk.virtualWrite(V7, s3);
Blynk.virtualWrite(V8, s4);
Blynk.virtualWrite(V9, s5);
Blynk.virtualWrite(V10, s6);
Blynk.virtualWrite(V11, s7); //add or delete if you need more or less
}