Skip to content

Commit

Permalink
Merge branch 'devices'
Browse files Browse the repository at this point in the history
  • Loading branch information
g-zajac committed Dec 18, 2018
2 parents 384573e + eef283d commit 4ebce1d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

typedef struct _DD {
const int esp_chip_id;
const int id;
} device_details ;

// current
const device_details devices[] = {
{0x00147593, 241},
{0x0029DEAD, 242},
{0x0029DCAB, 243},
{0x00D2F1AE, 244},
{0x0000AEDD, 245},
{0x0029DEF8, 246},
{0x0000A7EB, 247},
{0x00010D63, 248},
{0x00010DC0, 249},
{0, 240} // default if not defined above
};
36 changes: 33 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define DEBUG_HARDWARE_SERIAL
#define SERIAL_SPEED 115200
#define CODE_VERSION 1.3
#define CODE_VERSION 1.4
#define HOSTNAME "costume01"

#include <Arduino.h>
Expand All @@ -9,14 +9,21 @@
/* credentials.h example:
const char* ssid = "network_name";
const char* password = "password";
const IPAddress ip(10,10,10,101); //ip address of the unit
IPAddress gateway(10,0,100,1);
*/

#include <ArduinoOTA.h>
// |--------------|-------|---------------|--|--|--|--|--|
// ^ ^ ^ ^ ^
// Sketch OTA update File system EEPROM WiFi config (SDK)

extern "C"{
#include "user_interface.h" //NOTE needed for esp_system_info Since the include file from SDK is a plain C not a C++
}
#include "devices.h"
IPAddress deviceip;
int unit_ID;

void setup() {
#ifdef DEBUG_HARDWARE_SERIAL
Serial.begin(SERIAL_SPEED);
Expand All @@ -41,8 +48,31 @@ void setup() {
Serial.println("Starting Setup");
#endif

//---------------------------- WiFi --------------------------------------------
// determine IP address based on devices.h definitions
int chip_id = ESP.getChipId();
const device_details *device = devices;
for (; device->esp_chip_id != 0; device++) {
//Serial.printf("chip_id %X = %X?\n", chip_id, device->esp_chip_id);
if (device->esp_chip_id == chip_id)
break;
}
if (device->esp_chip_id == 0) {
while(1) {
#ifdef DEBUG_HARDWARE_SERIAL
Serial.println("Could not obtain a chipId we know. Means we dont know what id/IP address to asign. Fail");
Serial.printf("This ESP8266 Chip id = 0x%08X\n", chip_id);
#endif
}
}
deviceip = IPAddress(gateway);
deviceip[3] = device->id;
#ifdef DEBUG_HARDWARE_SERIAL
Serial.print("found in devices list ID: "); Serial.println(deviceip[3]);
#endif

WiFi.mode(WIFI_STA);
WiFi.config(ip, gateway, subnet);
WiFi.config(deviceip, gateway, subnet);
WiFi.begin(ssid, password);

while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Expand Down

0 comments on commit 4ebce1d

Please sign in to comment.