Arduino Forum

Topics => Home Automation and Networked Objects => Topic started by: SierraGolfMike on Apr 10, 2019, 05:50 pm

Title: ESP8266 operation
Post by: SierraGolfMike on Apr 10, 2019, 05:50 pm
I have the the ESP8266 development board shown.(tried to attache a photo but it would not attached, the Board is a Wemos D1 clone) I have created Adafruit and IFTTT accounts and set everything up as instructed. Instructions to Google Home are reflected in the Adafruit IO feeds but not happens with my physical connections. only one of the two blue LEDs is lit. I was using the code in the attached .ino file:


When I upload the sketch it connects to the wifi, gives me an IP address and MQTT connects! But then nothing on the board at all.

Any help would be much appreciated
Title: Re: ESP8266 operation
Post by: tasmod on Apr 10, 2019, 06:22 pm
What does the serial monitor print out?

Do you get the same as the window in the instructions if you flip your switch in the dashboard?  Have you linked your IFTT account as per instructions?
Title: Re: ESP8266 operation
Post by: SierraGolfMike on Apr 10, 2019, 06:46 pm
What does the serial monitor print out?

Do you get the same as the window in the instructions if you flip your switch in the dashboard?  Have you linked your IFTT account as per instructions?
The serial monitor prints Got: ON or Got: OFF for each toggle if I ask Google and if I flip the switch in the dashboard, which proves that the IFTTT account is linked.
Title: Re: ESP8266 operation
Post by: tasmod on Apr 10, 2019, 07:20 pm
So it is reaching the loop but not actioning the relay due to not receiving the 'state'.

As a test alter the line

 digitalWrite(Relay1, Lamp1_State);

to

 digitalWrite(Relay1, HIGH);

and see if this fires the relay.
Title: Re: ESP8266 operation
Post by: SierraGolfMike on Apr 10, 2019, 11:45 pm
So it is reaching the loop but not actioning the relay due to not receiving the 'state'.

As a test alter the line

 digitalWrite(Relay1, Lamp1_State);

to

 digitalWrite(Relay1, HIGH);

and see if this fires the relay.
Yes! when I ask Google to turn relay one on it does turn on!
Title: Re: ESP8266 operation
Post by: tasmod on Apr 11, 2019, 10:34 am
OK so progress.

Seems the atoi not working as expected so let's add a test line.

Add this and let me know what the serial monitor says the number is for on/off.

Code: [Select]


Serial.println(Lamp1.State);



just before

Code: [Select]


digitalWrite(Relay1, Lamp1_State);



What should be happening is the atoi is supposed to change the characters to an int of either 0 or 1 to relate to LOW(0) or HIGH(1) for the relay.

We could actually just do an 'if' statement for the ON / OFF but I would like to see what is actually happening.
Title: Re: ESP8266 operation
Post by: tasmod on Apr 11, 2019, 11:07 am
This is what I meant by the 'if' statement should you want to test it. (I don't use Google I use Alexa)

Code: [Select]

    if (subscription == &Lamp1) {
      Serial.print(F("Got: "));
      Serial.println((char *)Lamp1.lastread);

      if ((char *)Lamp1.lastread) == "ON"){
        digitalWrite(Relay1, HIGH);
      }
      if ((char *)Lamp1.lastread) == "OFF"){
        digitalWrite(Relay1, LOW);
      }
Title: Re: ESP8266 operation
Post by: tasmod on Apr 11, 2019, 11:32 am
OK.  I did an 'atoi' test sketch and the ON/OFF characters always evaluate to 0 which in your case equals OFF.

So try the 'if' code and see if it works for you.

Maybe one of the more advanced members will come along and explain the 'atoi' not evaluating.
Title: Re: ESP8266 operation
Post by: tasmod on Apr 11, 2019, 02:16 pm
Just a thought, in your block settings for the toggle switch are your button labels as per example?

They should be 0 and 1 as these are the characters passed. They are passed as characters "0" and "1" which the 'atoi' converts to numbers 0 and 1

If you used ON/OFF instead they will evaluate to 0 as that isn't what is expected by the 'atoi' line. 

Title: Re: ESP8266 operation
Post by: SierraGolfMike on Apr 11, 2019, 03:40 pm
Just a thought, in your block settings for the toggle switch are your button labels as per example?

They should be 0 and 1 as these are the characters passed. They are passed as characters "0" and "1" which the 'atoi' converts to numbers 0 and 1

If you used ON/OFF instead they will evaluate to 0 as that isn't what is expected by the 'atoi' line.  


I sussed that out earlier and did not have time to post a reply to you. When I realised what the atom was doing, I changed the data that google sends to 0 and 1.

Many thanks for taking the time to post, it is much appreciated on this steep learning curve.

You may be able to help further, if you don't mind? In the sketch the pins used are 6,5,2,and 1, Relay1 works on pin D12/MSIO/D6, Relay2 works on pin D13/SCK/D5, relay3 works on pin D14/SDA and Relay4 does not work on any of the pins. Any ideas on what other pins are controllable from the ESP8266? Photo of board attached.
Title: Re: ESP8266 operation
Post by: SierraGolfMike on Apr 11, 2019, 04:12 pm
I have tried changing D1 to D3, D4, D7 & D8 without success any higher and it says D* was not declared in this scope.
Title: Re: ESP8266 operation
Post by: SierraGolfMike on Apr 11, 2019, 04:37 pm
It turns out Google does not like "four" said in a Scottish accent. It would appear that Pin D1 translates to Pin D15/SCL. Is there a list anywhere to tell you which pins map to which?
Title: Re: ESP8266 operation
Post by: tasmod on Apr 11, 2019, 04:50 pm
I would have expected D1 to be one of your serial pins.  It's an odd numbering to be sure.

try this

https://cyaninfinite.com/getting-started-with-the-wemos-d1-esp8266-wifi-board/#Pinouts
Title: Re: ESP8266 operation
Post by: SierraGolfMike on Apr 11, 2019, 05:02 pm
Yeah, numbering is very strange, but I now have four pins that I can control and probably won't need any more.

Once again, many thanks for your help in my quest to learn some basic home automation.