Browse code

modificare cale/nume fisier

Andrei Bucur authored on 01/03/2018 13:48:20
Showing 1 changed files
1 1
deleted file mode 100755
... ...
@@ -1,116 +0,0 @@
1
-#include <FS.h>
2
-#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
3
-#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson
4
-
5
-//needed for library
6
-#include <ESP8266WebServer.h>
7
-#include <DNSServer.h>
8
-
9
-// Constants
10
-const int TRIGGER_PIN = 0; // D3 on NodeMCU and WeMos.
11
-
12
-// Variables
13
-const char* set_mqtt_user="exwrgq";
14
-const char* set_mqtt_devid="2638";
15
-
16
-// Default configuration values
17
-char mqtt_user[9]; //le va lua din FS
18
-char mqtt_devid[5]; //le va lua din FS
19
-
20
-// Function Prototypes
21
-bool readConfigFile();
22
-bool writeConfigFile();
23
-
24
-// Setup function
25
-void setup() {
26
-  // Put your setup code here, to run once
27
-  Serial.begin(115200);
28
-  Serial.println("\n Starting");
29
-
30
-  // Initialize trigger pins
31
-  pinMode(TRIGGER_PIN, INPUT_PULLUP);
32
-
33
-  // Mount the filesystem
34
-  bool result = SPIFFS.begin();
35
-  //Serial.println("SPIFFS opened: " + result);
36
-
37
-  if (readConfigFile()) {
38
-    Serial.print("User:");
39
-    Serial.println(mqtt_user);
40
-    Serial.print("devid:");
41
-    Serial.println(mqtt_devid);
42
-  }
43
-  //WiFi.printDiag(Serial); //Remove this line if you do not want to see WiFi password printed
44
-
45
-}
46
-
47
-// Loop function
48
-
49
-void loop() {
50
-  // is configuration portal requested?
51
-  if (digitalRead(TRIGGER_PIN) == LOW) {
52
-     Serial.println("Configuration portal requested");
53
-    writeConfigFile();
54
-     Serial.println("writeconfigfile...done");
55
-  }
56
-}
57
-
58
-bool readConfigFile() {
59
-  // this opens the config file in read-mode
60
-  File f = SPIFFS.open("/config.json", "r");
61
-  
62
-  if (!f) {
63
-    Serial.println("Configuration file not found");
64
-    return false;
65
-  } else {
66
-    // we could open the file
67
-    size_t size = f.size();
68
-    // Allocate a buffer to store contents of the file.
69
-    std::unique_ptr<char[]> buf(new char[size]);
70
-
71
-    // Read and store file contents in buf
72
-    f.readBytes(buf.get(), size);
73
-    // Closing file
74
-    f.close();
75
-    // Using dynamic JSON buffer which is not the recommended memory model, but anyway
76
-    // See https://github.com/bblanchon/ArduinoJson/wiki/Memory%20model
77
-    DynamicJsonBuffer jsonBuffer;
78
-    // Parse JSON string
79
-    JsonObject& json = jsonBuffer.parseObject(buf.get());
80
-    // Test if parsing succeeds.
81
-    if (!json.success()) {
82
-      Serial.println("JSON parseObject() failed");
83
-      return false;
84
-    }
85
-    json.printTo(Serial);
86
-    strcpy(mqtt_user, json["mqtt_user"]);
87
-    strcpy(mqtt_devid, json["mqtt_devid"]);
88
-  }
89
-  return true;
90
-}
91
-
92
-bool writeConfigFile() {
93
-  Serial.println("Saving config file");
94
-  DynamicJsonBuffer jsonBuffer;
95
-  JsonObject& json = jsonBuffer.createObject();
96
-
97
-  // JSONify local configuration parameters
98
-  json["mqtt_user"] = set_mqtt_user;
99
-  json["mqtt_devid"] = set_mqtt_devid;
100
-
101
-  // Open file for writing
102
-  File f = SPIFFS.open("/config.json", "w");
103
-  if (!f) {
104
-    Serial.println("Failed to open config file for writing");
105
-    return false;
106
-  }
107
-
108
-  json.prettyPrintTo(Serial);
109
-  // Write data to file and close it
110
-  json.printTo(f);
111
-  f.close();
112
-
113
-  Serial.println("\nConfig file was successfully saved");
114
-  return true;
115
-}
116
-