mirror of
https://github.com/anklimov/lighthub
synced 2025-12-12 22:59:49 +03:00
Improve multiplatform building stuff
This commit is contained in:
@@ -64,11 +64,9 @@ ESP32
|
||||
PWM Out
|
||||
|
||||
*/
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "options.h"
|
||||
#include "utils.h"
|
||||
#include "homiedef.h"
|
||||
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
DueFlashStorage EEPROM;
|
||||
@@ -80,18 +78,12 @@ EthernetClient ethClient;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <user_interface.h>
|
||||
WiFiClient ethClient;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <EEPROM.h>
|
||||
#include "Ethernet3.h"
|
||||
WiFiClient ethClient;
|
||||
NRFFlashStorage EEPROM;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32F1
|
||||
@@ -99,7 +91,7 @@ WiFiClient ethClient;
|
||||
//#include <EthernetClient.h>
|
||||
//#include "UIPEthernet.h"
|
||||
//#include "UIPUdp.h"
|
||||
#include <SPI.h>
|
||||
//#include <SPI.h>
|
||||
#include <Ethernet_STM.h>
|
||||
|
||||
#include "Dns.h"
|
||||
@@ -110,7 +102,6 @@ EthernetClient ethClient;
|
||||
#endif
|
||||
|
||||
#ifdef NRF5
|
||||
#include <NRFFlashStorage.h>
|
||||
NRFFlashStorage EEPROM;
|
||||
EthernetClient ethClient;
|
||||
#endif
|
||||
@@ -171,7 +162,9 @@ bool wifiInitialized;
|
||||
|
||||
int mqttErrorRate;
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
||||
#endif
|
||||
|
||||
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||
debugSerial<<F("\n[")<<topic<<F("] ");
|
||||
@@ -548,7 +541,7 @@ void onInitialStateInitLAN() {
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if(!wifiInitialized) {
|
||||
WiFi.mode(WIFI_STA);
|
||||
// WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD);
|
||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
@@ -740,7 +733,7 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
||||
void printCurentLanConfig() {
|
||||
debugSerial << F("Current LAN config(ip,dns,gw,subnet):");
|
||||
printIPAddress(Ethernet.localIP());
|
||||
printIPAddress(Ethernet.dnsServerIP());
|
||||
// printIPAddress(Ethernet.dnsServerIP());
|
||||
printIPAddress(Ethernet.gatewayIP());
|
||||
printIPAddress(Ethernet.subnetMask());
|
||||
}
|
||||
@@ -935,22 +928,32 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
||||
{
|
||||
IPAddress ip0(0, 0, 0, 0);
|
||||
IPAddress ip;
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(NRF5)
|
||||
DNSClient dns;
|
||||
#define inet_aton(cp, addr) dns.inet_aton(cp, addr)
|
||||
#else
|
||||
#define inet_aton(cp, addr) inet_aton(cp, addr)
|
||||
#endif
|
||||
|
||||
switch (arg_cnt) {
|
||||
case 5:
|
||||
if (dns.inet_aton(args[4], ip)) saveFlash(OFFSET_MASK, ip);
|
||||
if (inet_aton(args[4], ip)) saveFlash(OFFSET_MASK, ip);
|
||||
else saveFlash(OFFSET_MASK, ip0);
|
||||
case 4:
|
||||
if (dns.inet_aton(args[3], ip)) saveFlash(OFFSET_GW, ip);
|
||||
if (inet_aton(args[3], ip)) saveFlash(OFFSET_GW, ip);
|
||||
else saveFlash(OFFSET_GW, ip0);
|
||||
case 3:
|
||||
if (dns.inet_aton(args[2], ip)) saveFlash(OFFSET_DNS, ip);
|
||||
if (inet_aton(args[2], ip)) saveFlash(OFFSET_DNS, ip);
|
||||
else saveFlash(OFFSET_DNS, ip0);
|
||||
case 2:
|
||||
if (dns.inet_aton(args[1], ip)) saveFlash(OFFSET_IP, ip);
|
||||
if (inet_aton(args[1], ip)) saveFlash(OFFSET_IP, ip);
|
||||
else saveFlash(OFFSET_IP, ip0);
|
||||
break;
|
||||
case 1:
|
||||
|
||||
case 1: //dynamic IP
|
||||
saveFlash(OFFSET_IP,ip0);
|
||||
/*
|
||||
IPAddress current_ip = Ethernet.localIP();
|
||||
IPAddress current_mask = Ethernet.subnetMask();
|
||||
IPAddress current_gw = Ethernet.gatewayIP();
|
||||
@@ -963,7 +966,7 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
||||
printIPAddress(current_ip);
|
||||
printIPAddress(current_dns);
|
||||
printIPAddress(current_gw);
|
||||
printIPAddress(current_mask);
|
||||
printIPAddress(current_mask); */
|
||||
}
|
||||
debugSerial<<F("Saved\n");
|
||||
}
|
||||
@@ -1104,9 +1107,13 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
return READ_RE_CONFIG;//-11;
|
||||
}
|
||||
#endif
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||
String response;
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_ESP32)
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
WiFiClient configEthClient;
|
||||
#else
|
||||
EthernetClient configEthClient;
|
||||
#endif
|
||||
String response;
|
||||
HttpClient htclient = HttpClient(configEthClient, configServer, 80);
|
||||
//htclient.stop(); //_socket =MAX
|
||||
htclient.setHttpResponseTimeout(4000);
|
||||
@@ -1142,7 +1149,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
}
|
||||
#endif
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
HTTPClient httpClient;
|
||||
String fullURI = "http://";
|
||||
fullURI+=configServer;
|
||||
@@ -1194,6 +1201,8 @@ void postTransmission() {
|
||||
}
|
||||
|
||||
void setup_main() {
|
||||
//Serial.println("Hello");
|
||||
//delay(1000);
|
||||
setupCmdArduino();
|
||||
printFirmwareVersionAndBuildOptions();
|
||||
|
||||
|
||||
105
lighthub/main.h
105
lighthub/main.h
@@ -1,5 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "options.h"
|
||||
#if defined(__SAM3X8E__)
|
||||
#include <DueFlashStorage.h>
|
||||
#include <watchdog.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
#include "HTTPClientAVR.h"
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <EEPROM.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <user_interface.h>
|
||||
#endif
|
||||
|
||||
#if defined ARDUINO_ARCH_ESP32
|
||||
//#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
//#include <EEPROM.h>
|
||||
#include <NRFFlashStorage.h>
|
||||
#include <HttpClient.h>
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <DNSServer.h>
|
||||
|
||||
#define Ethernet WiFi
|
||||
#endif
|
||||
|
||||
#ifdef NRF5
|
||||
#include <NRFFlashStorage.h>
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#define wdt_res() watchdogReset()
|
||||
@@ -56,18 +99,6 @@
|
||||
#include "DallasTemperature.h"
|
||||
#endif
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <PubSubClient.h>
|
||||
#include <SPI.h>
|
||||
#include "utils.h"
|
||||
#include <string.h>
|
||||
#include "aJSON.h"
|
||||
#include <Cmd.h>
|
||||
#include "stdarg.h"
|
||||
#include "item.h"
|
||||
#include "inputs.h"
|
||||
|
||||
|
||||
#ifndef MODBUS_DISABLE
|
||||
#include <ModbusMaster.h>
|
||||
#endif
|
||||
@@ -76,57 +107,23 @@
|
||||
#include "FastLED.h"
|
||||
#endif
|
||||
|
||||
#include "Dns.h"
|
||||
//#include "hsv2rgb.h"
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#include <DueFlashStorage.h>
|
||||
#include <watchdog.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
#include "HTTPClientAVR.h"
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <EEPROM.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _owire
|
||||
|
||||
#include "owTerm.h"
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_dmxin) || defined(_dmxout) || defined (_artnet)
|
||||
|
||||
#include "dmx.h"
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266) || defined(NRF5)
|
||||
|
||||
#ifdef Wiz5500
|
||||
#include <Ethernet2.h>
|
||||
#else
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(NRF5)
|
||||
#include <Ethernet.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <SPI.h>
|
||||
//#include <Ethernet3.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _artnet
|
||||
#include <Artnet.h>
|
||||
@@ -136,6 +133,18 @@
|
||||
#include "sd_card_w5100.h"
|
||||
#endif
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "utils.h"
|
||||
#include "homiedef.h"
|
||||
#include <PubSubClient.h>
|
||||
#include <SPI.h>
|
||||
#include <string.h>
|
||||
#include "aJSON.h"
|
||||
#include <Cmd.h>
|
||||
#include "stdarg.h"
|
||||
#include "item.h"
|
||||
#include "inputs.h"
|
||||
|
||||
#ifdef _artnet
|
||||
extern Artnet *artnet;
|
||||
#endif
|
||||
|
||||
@@ -129,6 +129,10 @@
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#undef _dmxin
|
||||
#undef _modbus
|
||||
#undef _dmxout
|
||||
#undef modbusSerial
|
||||
#endif
|
||||
|
||||
#ifndef _dmxout
|
||||
|
||||
@@ -110,7 +110,7 @@ unsigned long freeRam() {
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#if defined(__SAM3X8E__)
|
||||
extern char _end;
|
||||
extern "C" char *sbrk(int i);
|
||||
|
||||
@@ -265,5 +265,67 @@ void ReadUniqueID( unsigned int * pdwUniqueID )
|
||||
}
|
||||
|
||||
|
||||
int inet_aton(const char* aIPAddrString, IPAddress& aResult)
|
||||
{
|
||||
// See if we've been given a valid IP address
|
||||
const char* p =aIPAddrString;
|
||||
while (*p &&
|
||||
( (*p == '.') || (*p >= '0') || (*p <= '9') ))
|
||||
{
|
||||
p++;
|
||||
}
|
||||
|
||||
if (*p == '\0')
|
||||
{
|
||||
// It's looking promising, we haven't found any invalid characters
|
||||
p = aIPAddrString;
|
||||
int segment =0;
|
||||
int segmentValue =0;
|
||||
while (*p && (segment < 4))
|
||||
{
|
||||
if (*p == '.')
|
||||
{
|
||||
// We've reached the end of a segment
|
||||
if (segmentValue > 255)
|
||||
{
|
||||
// You can't have IP address segments that don't fit in a byte
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
aResult[segment] = (byte)segmentValue;
|
||||
segment++;
|
||||
segmentValue = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Next digit
|
||||
segmentValue = (segmentValue*10)+(*p - '0');
|
||||
}
|
||||
p++;
|
||||
}
|
||||
// We've reached the end of address, but there'll still be the last
|
||||
// segment to deal with
|
||||
if ((segmentValue > 255) || (segment > 3))
|
||||
{
|
||||
// You can't have IP address segments that don't fit in a byte,
|
||||
// or more than four segments
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
aResult[segment] = (byte)segmentValue;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||
|
||||
@@ -42,3 +42,4 @@ void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int
|
||||
int log(const char *str, ...);
|
||||
void printFloatValueToStr(float value, char *valstr);
|
||||
void ReadUniqueID( unsigned int * pdwUniqueID );
|
||||
int inet_aton(const char* aIPAddrString, IPAddress& aResult);
|
||||
|
||||
Reference in New Issue
Block a user