Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
eugenelai
@eugenelai
Hi guys. I'm having issues with a PIR sensor and MQTT. I've got it all up and running now, however the motion sensor return 1 or 0 in the payload depending on whether motion is detected. I'd like the payload to say on/off instead. however when i add a if statement to set a variable to ON/OFF it just gets stuck in a loop. Code below:
    if (checkMotion(newMotion, motion))
    {
      motion = newMotion;
      Serial.print("Motion sensor: ");
      Serial.println(String(motion).c_str());
      client.publish(motion_topic, String(motion).c_str(), true);
      if (motion = 1)
      {
        motionState = "ON";                
      }     

      if (motion == 0)
      {
        motionState = "OFF";        
      }
      Serial.print("ReadibleMotion sensor: ");
      Serial.println(motionState);
     }
Using the code above it just gets stuck in a loop and prints "readible Motion sensor"
Not sure why its getting stuck in the loop
can anyone help out a brother here?
eugenelai
@eugenelai
never mind. i needed at == instead of = for the if statement
brutzler
@brutzler
Does anybody know, why i often get a "....file could not be replaced" , on compiling a sketch?
In that case there is a file like this stored:
mysketch.ino8450644836749833574.tmp
Oleg Perevyshin
@mcmega

This is a function to update the file system and sketch

bool _updateFW(bool updTarget) {
  // httpClient.begin
  // check 200
  // Update.setMD5
  // Update.begin
  if (!Update.writeStream(*httpClient.getStreamPtr())) {
    Update.printError(Serial);
    return false;
  } else if (progress != Update.progress() * 100 / Update.size()) {
    progress = Update.progress() * 100 / Update.size();
    sendWS(NULL, "updPrgESP", String(progress));
  }
  // Update.end
  httpClient.end();
  return true;
}

Here I get only when the update is 100%

else if (progress != Update.progress() * 100 / Update.size()) {
    progress = Update.progress() * 100 / Update.size();
    sendWS(NULL, "updPrgESP", String(progress));
  }

How can I get firmware progress?

Develo
@devyte
Use the updater class callback system (::onblah methods)
Oleg Perevyshin
@mcmega
How to do it, where to use it? Help.
I run the update through the UART command and download bin files from remote server (create httpClient for dounload). The web server is not used.
How to make callback?
Develo
@devyte
Look at the Updater class in the .h in the repo
Use the source, Luke!
Oleg Perevyshin
@mcmega
I looked update.h, but did not understand how it was done callback.
Clemens Kirchgatterer
@everslick
@mcmega size_t UpdaterClass::writeStream(Stream &data) blocks until the whole firmware was written, so you cannot get a progress callback this way.
you would have to use Update::write(...) and feed it piece by piece, so you can show your progress in your UI.
Oleg Perevyshin
@mcmega
Help please. How to use Update::write(...)? Update.writeStream() do not use?
Oleg Perevyshin
@mcmega
@everslick Show me, how to replace Update.writeStream by Update.write
if (Update.write(???, ???) != Update.size()) {
    if (progress != int(Update.progress() * 100 / Update.size())) {
      progress = int(Update.progress() * 100 / Update.size());
      sendWS(NULL, "updPrg", String(progress));
    }
  }
Clemens Kirchgatterer
@everslick
Update.write() takes a pointer to the chunk of data and the length of that chunk - where ever that data is coming from. the Update.size() in the first if statement should of course be replaced by the chunk size as well.
Oleg Perevyshin
@mcmega
Where can I find the block size? Or set it manually?
Clemens Kirchgatterer
@everslick
i dunno where you get your update from, so i cannot tell you. when it is uploaded via http server on the esp8266 it is in the upload object that lives within the webserver... if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Oleg Perevyshin
@mcmega
It works, maybe someone will need it!
Updating the file system and sketch from the remote server with checking md5 and returning the progress in percent.
void updateESP() {
  sendWS(NULL, "infoMessage", "FFS Update...");
  if (_updateFW(true)) {
    delay(250);
    sendWS(NULL, "infoMessage", "ESP Update...");
    if (_updateFW(false)) {
      sendWS(NULL, "infoMessage", "All Updates Completed");
      delay(250);
    }
  }
}

bool _updateFW(bool updTarget) {
  udp.close();
  HTTPClient httpClient;
  httpClient.useHTTP10(true);
  httpClient.setTimeout(5000);
  char url[65];
  sprintf(url, "http://%s/%s-%d-%s.bin", OTA_HOST, DEVICE_MODEL, latVer, updTarget ? "ffs" : "esp");
  httpClient.begin(url);
  if (httpClient.GET() != HTTP_CODE_OK) {
    sendWS(NULL, "infoMessage", "Unable to fetch, please reboot the device and try again");
    return false;
  }
  int httpSize = httpClient.getSize();
  if (!Update.setMD5(updTarget ? ffsMD5 : espMD5)) {
    sendWS(NULL, "infoMessage", "Invalid MD5, please reboot the device and try again");
    return false;
  }
  if (!Update.begin(httpSize, updTarget ? U_SPIFFS : U_FLASH)) {
    sendWS(NULL, "infoMessage", "Incorrect startup conditions, please reboot the device and try again");
    return false;
  }
  uint8_t buff[1024] = { 0 };
  size_t sizePack;
  WiFiClient * stream = httpClient.getStreamPtr();
  while (httpClient.connected() && (httpSize > 0 || httpSize == -1)) {
    sizePack = stream->available();
    if (sizePack) {
      int c = stream->readBytes(buff, ((sizePack > sizeof(buff)) ? sizeof(buff) : sizePack));
      Update.write(buff, c);
      if (httpSize > 0)
        httpSize -= c;
    }
    if (progress != int(Update.progress() * 100 / httpClient.getSize())) {
      progress = int(Update.progress() * 100 / httpClient.getSize());
      updTarget ? sendWS(NULL, "updPrgFFS", String(progress)) : sendWS(NULL, "updPrgESP", String(progress));
    }
  }
  if (!Update.end()) {
    sendWS(NULL, "infoMessage", "Invalid completion conditions, please reboot the device and try again");
    return false;
  }
  httpClient.end();
  return true;
}
hoangtrung101
@hoangtrung101
how to convert string IP to IPAddress in ESP8266/arduino ide
Martin Ayotte
@martinayotte
@hoangtrung101 look at IPAddress.fromString()
hoangtrung101
@hoangtrung101
@martinayotte thanks
1rabbit
@1rabbit
hi i'm trying to contact the author of https://github.com/martin-ger/esp_wifi_repeater for a small suggestion about power management
1rabbit
@1rabbit
nevermind i found how to
Myles McNamara
@tripflex
hey guys, so after having issues with NTPClientLib i read this issue, and found that it appears with 2.4.0 that almost all libs for NTP will more than likely not function correctly anymore … stelgenhof/NTPClient#5
does anybody have any sites or documentation, or maybe even just an example, of what I can do to get NTP functional again? can’t seem to find much on it
Myles McNamara
@tripflex
now just need to figure out how to force it to update from ntp
Cubie-Chan
@CubieChansArt_twitter
Hey, can anyone help me with my arduino? i have a robot that can drive and now i wanna do the mapping. so it captures the way it drove. but im a bit confused
mega-hz
@mega-hz
hello, does anyone know why my esp is still not with the fixed IP Adress?
// WiFi.config(ip, dns, gateway, subnet);
WiFi.mode(WIFI_STA);
IPAddress ip(192, 168, 2, 240); // where xx is the desired IP Address
IPAddress gateway(192, 168, 2, 1); // set gateway to match your network
IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your
IPAddress dns(192, 168, 2, 1); // set dns


WiFi.begin(ssid, passwort);
Aaron N.
@porkyneal
@mega-hz, you have just created variables to hold your IP details, need to use WiFi.config() to make them used.
ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
mega-hz
@mega-hz
ahh, ok, works! thanks!
Victor Aprea
@vicatcu
FYI, there is a conversation going on in the Arduino developers list about File and Directory classes becoming normalized and they are looking for someone from the ESP8266 developer community to engage there if possible
just wanted to put feelers out, cheers
Me No Dev
@me-no-dev
@vicatcu thanks :)
bobcroft
@bobcroft
@CubieChansArt_twitter , Hi I assume you mean you want to record your robots position as it moves along. If you where looking at distances in tens of metre's you could use GPS. However, I guess you are looking at shorter distances, you could use a compass module to get direction and an encoder on a wheel to get distance. A wheel encoder could be as simple as a reed switch or Hall effect device fixed to the robot body and then a small magnet or magnets fixed to the wheel. One magnet would give a distance resolution of one wheel circumference. It all depends on what accuracy you are after. Signals from the sensors could then be wirelessly transmitted to a receiver unit for processing.
Mehrdad K
@mkeyno
hi guys
does anyone know successful project to reading pulse tone and voice from a landline phone and transmission over wifi?
Daleon L
@Allwaysawake
Hey there I seem to be having a tad bit of trouble connecting to an Https via my Huzzah ESP8266, Can anyone help me...?
bobcroft
@bobcroft
@Allwaysawake Hi see the latest posting in the Arduino -ESP32 group re connecting via Https using WiFiClientSecure.
Daleon L
@Allwaysawake
@bobcroft is the Arduino-ESP32 the same as the ESP-8266...?
bobcroft
@bobcroft
@Allwaysawake , No the ESP32 hardware is very different from the ESP8266. At the moment there is a lot of work being done so that code / libraries developed for the ESP8266 can run on the newer and more capable ESP32. However, there is no need to use an ESP32 if an ESP8266 will do the job. I suggested you look at the ESP32 solution to running https as it MAY help you run it on the ESP8266. I don't use https services at the moment so I can't help further. There are some very clever and very good programmers on these forums who may be able to give you a definite answer. However, as always, you should also search the net for an answer as well.
rodrigocirilo
@rodrigocirilo

Hello, can anyone help.

I have several ESP8266 working as clients, connected in a server (C # app) through a fixed IP, but this IP if not more will be fixed and a DDNS server will be used.

How do I tell ESP that it has to connect to a DDNS and not an IP? (arduino IDE)

Cliente.connect(server, PORTA);

server is a IP (192.168.1.16) and PORTA is a port (9000)
DDNS exemple testone.dyndns.org
Daleon L
@Allwaysawake
@bobcroft thanks for the feedback.
rodrigocirilo
@rodrigocirilo

Alright, try this code. This should work out pretty well for you. If not, let me know. :)

#include <ESP8266WiFi.h>
  #define       LED0      2         // WIFI Module LED
//------------------------------------------------------------------------------------
String Message="";
//------------------------------------------------------------------------------------
// Authentication Variables
//------------------------------------------------------------------------------------
  char*         connect_to = "ssid";
  char*         pass = "password";
  IPAddress     qwertyServer(192,168,4,1);
  WiFiClient    qwertyClient;
//====================================================================================

  void setup()
  {        
    // Setting The Mode Of Pins ---------------------------------------------
    pinMode(LED0, OUTPUT);          // WIFI OnBoard LED Light
    digitalWrite(LED0, !LOW);       // Turn WiFi LED Off

    // Print Message Of I/O Setting Progress --------------------------------
    //Serial.println("\nI/O Pins Modes Set .... Done");

    // Starting To Connect --------------------------------------------------
    WiFi.mode(WIFI_STA);            // To Avoid Broadcasting An SSID
    WiFi.begin(connect_to, pass);          // The SSID That We Want To Connect To

    // Printing Message For User That Connetion Is On Process ---------------
    Serial.println("!--- Connecting To " + WiFi.SSID() + " ---!");

     // Setting The Serial Port ----------------------------------------------
    Serial.begin(9600);           // Computer Communication
    delay(500);
    Serial.print("\n");

    // WiFi Connectivity ----------------------------------------------------
    CheckConnectivity();            // Checking For Connection  
  }

//====================================================================================

  void loop()
  {

    if(WiFi.status() != WL_CONNECTED)
    {
        Serial.println("\nOops! Connection lost. Trying to reconnect " + String(WiFi.SSID()));
        Serial.println("");
        CheckConnectivity();
    }
    else if(qwertyClient.available() > 0)
    {
        ReadMessage();
        Serial.print(Message);

      qwertyClient.flush();
      }

  }
//====================================================================================

  void ReadMessage()
  {
      Message = "";
      Message = qwertyClient.readStringUntil('\r');
  }

//====================================================================================

  void CheckConnectivity()
  {
    while(WiFi.status() != WL_CONNECTED)
    {
      for(int i=0; i < 2; i++)
      {
        digitalWrite(LED0, !HIGH);
        delay(50);
        digitalWrite(LED0, !LOW);
        delay(550);
        Serial.print(".");
      }
      Serial.println("");
    }

  // Stop Blinking To Indicate Connected ----------------------------------
    digitalWrite(LED0, LOW);
    Serial.println("\n!-- Client Device Connected --!");
    Serial.print("\n\n");

    // Printing IP Address --------------------------------------------------
    Serial.println("Connected To      : " + String(WiFi.SSID()));
    Serial.println("Signal Strenght   : " + String(WiFi.RSSI()) + " dBm");
    Serial.print  ("Server IP Address : ");
    Serial.println(qwertyServer);
    Serial.print  ("Device IP Address : ");
    Serial.println(WiFi.localIP());

    // Conecting The Device As A Client -------------------------------------
    ClientRequest();

  }

//====================================================================================

  void ClientRequest()
  {
    // First Make Sure You Got Disconnected
    qwertyClient.stop();

    // If Sucessfully Connected Send Connection Message
    if(qwertyClient.connect(qwertyServer, 23))
    {
      delay(250);
      Serial.print("status\n");
      Serial.println    ("Connected");
      qwertyClient.println ("Connected");
    }
  }

This is the code I am currently using, with some simple modifications.
then I would need to change the IP of (qwertyServer) to a DDNS address, does a