Connected to WiFi but not online?

Hi, sorry - another newbie question I think. I have written some code to control a servo motor. I am using an Arduino uno board with a stackable 8266 WiFi shield on top.
I am trying to make a very simple app with one button to control the servo. When the button is on it rotates the servo 270 degrees, and when off it returns to 0.
IYesterday had a very similar bit of code turning an LED on and off and today I thought I would change it up and use a servo. I managed to get the LED to work as expected thanks to some help on here, so I know my boar can connect correctly to the internet but at the moment it just connects but never gives me the ready signal and never appears online on the Blynk cloud.

Any suggestions very gratefully received, thank you.

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_DEVICE_NAME "Servo"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>

char auth[] = "REDACTED";
char ssid[] = "REDACTED";
char pass[] = "REDACTED";

// or Software Serial on Uno, Nano...
 #include <SoftwareSerial.h>
 SoftwareSerial EspSerial(4, 5); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

Servo myservo; 

void setup()
{
  myservo.attach(9);
  myservo.write(0);

  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
 }
  
void loop()
{
    Blynk.run();
}

BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
         if (pinValue == 1) //if button on
 { myservo.write(270);// move servo to 270•
    }
           else // if button off
            
  myservo.write(0); // move servo to 0•

}

The output on the serial monitor is below…

   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on Arduino Uno

 #StandWithUkraine    https://bit.ly/swua


[658] Connecting to BT-SKATMF
[3865] AT version:1.2.0.0(Jul  1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec  2 2016 14:21:16
OK
[7171] +CIFSR:STAIP,"192.168.1.157"
+CIFSR:STAMAC,"58:bf:25:c6:1a:db"
[7179] Connected to WiFi

So you’ve created another template and device?
Are you using the Auth token that relates to this device?

I prefer to see people copying the three lines of Firmware configuration code from the Device Info tab, and pasting them directly into the top of the sketch.
Then, either having a line of code that says:

char auth[] = BLYNK_AUTH_TOKEN;

or changing this line:

to…

Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);

This way, it’s difficult to get the wrong template, device and Auth token combination.

Pete.

1 Like

Thanks Peter - I think I had all the right information in there but I deleted my template and device and started fresh again and with your code hints and it seems to have done the trick!

Thanks again!
Best
Dave.

1 Like

Sorry Peter - only thing now is that every 30seconds or so the servo moves a little bit?? I want it to sit without moving until I press the button? Any ideas??

Many thanks

Can you post your latest sketch?

Pete.

Absolutely… see below :slight_smile:

#define BLYNK_TEMPLATE_ID "TMPLe0hDosPX"
#define BLYNK_DEVICE_NAME "FoxFeeder"
#define BLYNK_AUTH_TOKEN "6w9F1Di16z1_SGYMolj6fDO-zdUG8uew"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>

char ssid[] = "BT-SKATMF";
char pass[] = "K3vrQCyxMFcuXg";

// or Software Serial on Uno, Nano...
 #include <SoftwareSerial.h>
 SoftwareSerial EspSerial(4, 5); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

Servo myservo; 

void setup()
{
  myservo.attach(9);
  myservo.write(0);

  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
 }
  
void loop()
{
    Blynk.run();
}

BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
         if (pinValue == 1) //if button on
 { myservo.write(270);// move servo to 270•
    }
           else // if button off
            
  myservo.write(0); // move servo to 0•

}

Hmm, can’t see any reason why the servo would be moving on its own. Maybe check the connections and ensure that your power connections to the board and the servo are sound, and adequate.

Pete.

OK cool - thanks, I will have a look and check everything. Just wanted to make sure there was nothing in my code that was effecting it!

Dear Sir
My ESP8266 is connected to wifi and searching–connecting to blynk.cloud but blynk console web and mobile deshboard is offline only. Yesterday it was working. Now again i went to quickstart from beginning but same condition. Paid Rs.2 for for plus plan. but still web and mobile deshboards are not online. Please guide urgently.

@Blink2023 instead of hijacking’s this topic, I’d suggest that you start a new “Need help with my project” topic and provide ALL of the information that is requested when you do this, and any additional information that may be useful in helping understand your problem.

Pete.

yesterday, system was working ok, for 24 hours after first started the system, but after that deshboard gone into offline mode. All the first 3 lines of token/template name etc are same at nodemcu as per deshboard data. there is message connecting to blynk.cloud : 80 . but mobile blynk page is offline only. I am owner at rokade.arvind@gmail.com Name Arvind Rokade

Pete.