Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Rasoul
#74208 Hi guys I just made my own pcb for esp8266 chip and i picked up all schematics from NodeMcu V1.0 .So Hardware is same as NodeMcu as far as i know ...
So here's the problem my codes works well with NodeMcu But when i upload it to my board every thing works except WiFi .
when i start esp as access point it shows in the wifi list of my phone but i can't connect to it . i think it can't assign ip for my phone
and again when i choose station mode and give it the right ssid and pass to connect my phone's hotspot that is near my board again it recognize all the stations around board but it can't connect to any of them . i've tested this with router too .
So how can i fix this ? I apreciate all of your answers

here is a code for station mode that doesn't work
Code: Select all/*******************************************************************
 *  An example of bot that receives commands and turns on and off  *
 *  an LED.                                                        *
 *                                                                 *
 *  written by Giacarlo Bacchio (Gianbacchio on Github)            *
 *  adapted by Brian Lough                                         *
 *******************************************************************/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

// Initialize Wifi connection to the router
char ssid[] = "XXXXXX";     // your network SSID (name)
char password[] = "YYYYYY"; // your network key

// Initialize Telegram BOT
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"  // your Bot Token (Get from Botfather)

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

const int ledPin = 13;
int ledStatus = 0;

void handleNewMessages(int numNewMessages) {
  Serial.println("handleNewMessages");
  Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    String chat_id = String(bot.messages[i].chat_id);
    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;
    if (from_name == "") from_name = "Guest";

    if (text == "/ledon") {
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      ledStatus = 1;
      bot.sendMessage(chat_id, "Led is ON", "");
    }

    if (text == "/ledoff") {
      ledStatus = 0;
      digitalWrite(ledPin, LOW);    // turn the LED off (LOW is the voltage level)
      bot.sendMessage(chat_id, "Led is OFF", "");
    }

    if (text == "/status") {
      if(ledStatus){
        bot.sendMessage(chat_id, "Led is ON", "");
      } else {
        bot.sendMessage(chat_id, "Led is OFF", "");
      }
    }

    if (text == "/start") {
      String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
      welcome += "This is Flash Led Bot example.\n\n";
      welcome += "/ledon : to switch the Led ON\n";
      welcome += "/ledoff : to switch the Led OFF\n";
      welcome += "/status : Returns current status of LED\n";
      bot.sendMessage(chat_id, welcome, "Markdown");
    }
  }
}


void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was Previously
  // connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  // attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
  delay(10);
  digitalWrite(ledPin, LOW); // initialize pin as off
}

void loop() {
  if (millis() > Bot_lasttime + Bot_mtbs)  {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    while(numNewMessages) {
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }

    Bot_lasttime = millis();
  }
}
User avatar
By mrburnette
#74238 It is poor forum etiquette to use !!!!!! in an attempt to get an answer. Most members will simply reject your begging and move-on. Just ask and post with a reasonable title.

Find an example of AP and make certain you can connect with your cellphone. There are thousands of examples on the web for AP and blinking a LED, on YouTube too.

I think I have an example on my projects page:
https://www.hackster.io/rayburne/projects
It is titled ESP8266 Access Point Using Arduino IDE
(It uses an OLED, but that can be left out of the circuit and the code will still work.)
https://www.hackster.io/rayburne/esp8266-access-point-using-arduino-ide-19f632
User avatar
By rudy
#74239
mrburnette wrote:Find an example of AP and make certain you can connect with your cellphone.

Yes. After you have that working, then you troubleshoot your code. Get a working starting point.
User avatar
By Rasoul
#74254
rudy wrote:
mrburnette wrote:Find an example of AP and make certain you can connect with your cellphone.

Yes. After you have that working, then you troubleshoot your code. Get a working starting point.

it doesn't work at all even with the simplest example of arduino for AP and STA modes ...