Cant figure out how to implement DS18b20 to 8266gateway directly
-
I am a bit confused how to work with sketches and libraries. I tried to read up at Mysensors.com but i just cant grasp it.
I want to have a DS18b20 and a relay connected to be able to make a thermostat directly connected to the gateway. but i get errors compiling the code.
I am sorry for this completely noob question but im been trying for 2days to find examples and copy paste and trying to patch it together to no avail.
If someone could point out the errors i made i will be on my way building
Arduino:1.8.11 Hourly Build 2019/12/16 10:04 (Mac OS X), Kort:"Generic ESP8285 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 1MB (FS:64KB OTA:~470KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200" /var/folders/j1/1s10733x6b1fgwcmf1mk0cf00000gp/T/arduino_modified_sketch_627661/GatewayESP8266.ino: In function 'void presentation()': GatewayESP8266:143:1: error: a function-definition is not allowed here before '{' token { ^ GatewayESP8266:149:1: error: a function-definition is not allowed here before '{' token { ^ GatewayESP8266:154:21: error: a function-definition is not allowed here before '{' token void presentation() { ^ GatewayESP8266:203:1: error: expected '}' at end of input } ^ exit status 1 a function-definition is not allowed here before '{' token This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
Below are my sketch
// Enable debug prints to serial monitor #define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 #define MY_GATEWAY_ESP8266 #define MY_WIFI_SSID "MySSID" #define MY_WIFI_PASSWORD "MyVerySecretPassword" // Enable UDP communication //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. #define MY_HOSTNAME "ESP8266_GW" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) //#define MY_IP_ADDRESS 192,168,178,87 // If using static ip you can define Gateway and Subnet address as well //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0 // The port to keep open on node server mode #define MY_PORT 5003 // How many clients should be able to connect to this gateway (default 1) #define MY_GATEWAY_MAX_CLIENTS 2 // Controller ip address. Enables client mode (default is "server" mode). // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org" // Enable inclusion mode //#define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) //#define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button //#define MY_INCLUSION_MODE_BUTTON_PIN D1 // Set blinking period //#define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED #include <MySensors.h> void setup() { // Setup locally attached sensors } void presentation() { // Present locally attached sensors here #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(0,V_TEMP); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } } void loop() { // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; } } sleep(SLEEP_TIME); } } void loop() { // Send locally attached sensors data here }```
-
@tjog From an initial glance, can recommend not touching any alcohol for a few days , and spend some time re-reading the basic intro, outline of sketches, and why they are sequenced the way they are, it is all in the guide here...
Follow that methodically, throwing pistons, crankshaft, etc. randomly into a box has never yet made a working engine....
You have SETUP, PRESENTATION, BEFORE, SETUP, PRESENTATION, LOOP, LOOP... There should only be one of each void in a logical sequence, BEFORE, PRESENTATION, SETUP, LOOP.
Defines, libraries and variables do not belong in PRESENTATION rather than before any voids are called.If you look again at the original sketch you copied, it's sequence and contents will be logically laid out and working, the only difference in your case is that it is a Gateway not a Node. The clue lies in the last LOOP "// Send locally attached sensors data here"....
Start slowly and methodically using the guide, and move the instructions to their correct places, but importantly understand why, it will help later...
-
Hahah regarding the alcohol i think thats the problem!
I will check everything again with your pointers, thanks for the answer
I actually had a second look after i posted and made some changes, i got a lot less errors but still wasnt able to compile. I will have a new pass
Thanks