Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Chapu206
#79486 Hola tengo un Nodemcu 1.0 V3 CH340 - al usar el ejemplo de ESP8266 / ConfigFile del IDE de Arduino cargo el programa con "ESP8266 Scketch Data Upload" - con el correspondiente archivo "config.json" dentro de la carpeta data. El problema es que el serial monitor me da el siguiente error "ets Jan 8 2013,rst cause:2, boot mode:(3,7) ets_main.c"

Librerias: Estoy usando la ultima versión de la librería ArduinoJson.h (versión 6.6.0 Beta) Probe con varias versiones anteriores y nada versión 5.10 etc.

IDE Arduino version 1.8.7

S.O. Windows 10 64 bits

Probe con otras placas de iguales caracteristicas "ESP8266 NodemCu 1.0 V3 CH340" libres de todo conexionado electonico y me da el mismo problema.

Conclusion: al no poder solucionar el problema mi idea seria hacer una prueba con una placa ESP8266 NodemCu 1.0 V2 CP2102. Si alguien tiene una idea mejor sera bienvenida.
Pego el código.
Desde ya muchas gracias.

Code: Select all// Created Aug 10, 2015 by Ivan Grokhotkov.
//
// This example code is in the public domain.

#include <ArduinoJson.h>
#include "FS.h"

bool loadConfig() {
  File configFile = SPIFFS.open("/config.json", "r");
  if (!configFile) {
    Serial.println("Failed to open config file");
    return false;
  }

  size_t size = configFile.size();
  if (size > 1024) {
    Serial.println("Config file size is too large");
    return false;
  }

  // Allocate a buffer to store contents of the file.
  std::unique_ptr<char[]> buf(new char[size]);

  // We don't use String here because ArduinoJson library requires the input
  // buffer to be mutable. If you don't use ArduinoJson, you may as well
  // use configFile.readString instead.
  configFile.readBytes(buf.get(), size);

  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& json = jsonBuffer.parseObject(buf.get());

  if (!json.success()) {
    Serial.println("Failed to parse config file");
    return false;
  }

  const char* serverName = json["serverName"];
  const char* accessToken = json["accessToken"];

  // Real world application would store these values in some variables for
  // later use.

  Serial.print("Loaded serverName: ");
  Serial.println(serverName);
  Serial.print("Loaded accessToken: ");
  Serial.println(accessToken);
  return true;
}

bool saveConfig() {
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& json = jsonBuffer.createObject();
  json["serverName"] = "api.example.com";
  json["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";

  File configFile = SPIFFS.open("/config.json", "w");
  if (!configFile) {
    Serial.println("Failed to open config file for writing");
    return false;
  }

  json.printTo(configFile);
  return true;
}

void setup() {
  Serial.begin(115200);
  Serial.println("");
  delay(1000);
  Serial.println("Mounting FS...");

  if (!SPIFFS.begin()) {
    Serial.println("Failed to mount file system");
    return;
  }


  if (!saveConfig()) {
    Serial.println("Failed to save config");
  } else {
    Serial.println("Config saved");
  }

  if (!loadConfig()) {
    Serial.println("Failed to load config");
  } else {
    Serial.println("Config loaded");
  }
}

void loop() {
}
User avatar
By Chapu206
#79515 Hi, I have a Nodemcu 1.0 V3 CH340 - when using the SAMPLE of the Arduino IDE / ESP8266 / ConfigFile . I load the program with "ESP8266 Scketch Data Upload" - with the corresponding file "config.json" inside the data folder. The problem is that the serial monitor gives me the following error "ets Jan 8 2013, rst cause: 2, boot mode: (3,7) ets_main.c"

Libraries: I am using the latest version of the ArduinoJson.h library (version 6.6.0 Beta) Probe with several previous versions and nothing version 5.10 etc.

IDE Arduino version 1.8.7

SW. Windows 10 64 bits

Probe with other plates of the same characteristics "ESP8266 NodemCu 1.0 V3 CH340" free of all electonic connection and it gives me the same problem.
Code: Select all#include <ArduinoJson.h>
#include "FS.h"

bool loadConfig() {
  File configFile = SPIFFS.open("/config.json", "r");
  if (!configFile) {
    Serial.println("Failed to open config file");
    return false;
  }

  size_t size = configFile.size();
  if (size > 1024) {
    Serial.println("Config file size is too large");
    return false;
  }

  // Allocate a buffer to store contents of the file.
  std::unique_ptr<char[]> buf(new char[size]);

  // We don't use String here because ArduinoJson library requires the input
  // buffer to be mutable. If you don't use ArduinoJson, you may as well
  // use configFile.readString instead.
  configFile.readBytes(buf.get(), size);

  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& json = jsonBuffer.parseObject(buf.get());

  if (!json.success()) {
    Serial.println("Failed to parse config file");
    return false;
  }

  const char* serverName = json["serverName"];
  const char* accessToken = json["accessToken"];

  // Real world application would store these values in some variables for
  // later use.

  Serial.print("Loaded serverName: ");
  Serial.println(serverName);
  Serial.print("Loaded accessToken: ");
  Serial.println(accessToken);
  return true;
}

bool saveConfig() {
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& json = jsonBuffer.createObject();
  json["serverName"] = "api.example.com";
  json["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";

  File configFile = SPIFFS.open("/config.json", "w");
  if (!configFile) {
    Serial.println("Failed to open config file for writing");
    return false;
  }

  json.printTo(configFile);
  return true;
}

void setup() {
  Serial.begin(115200);
  Serial.println("");
  delay(1000);
  Serial.println("Mounting FS...");

  if (!SPIFFS.begin()) {
    Serial.println("Failed to mount file system");
    return;
  }


  if (!saveConfig()) {
    Serial.println("Failed to save config");
  } else {
    Serial.println("Config saved");
  }

  if (!loadConfig()) {
    Serial.println("Failed to load config");
  } else {
    Serial.println("Config loaded");
  }
}

void loop() {
}
User avatar
By QuickFix
#79519 Are you sure you've copied the correct message, since this is not an error. :?

Chapu206 wrote:"ets Jan 8 2013, rst cause: 2, boot mode: (3,7) ets_main.c"

This reset code means that your ESP8266 has reset via an external reset (via the reset button) or that the ESP is waking up from deep-sleep.
When you do post error messages here on the forum, make sure you post the actual message (do a copy-paste) and not something that looks similar to the message (because it really isn't).

As for the JSON-library: double check that you're using the ESP8266 compatible version, you often cannot use pure Arduino code without alterations. :idea: