Build preconfigured ESP with MQTT and sensors/actuators
Moderators: grovkillen, Stuntteam, TD-er
Build preconfigured ESP with MQTT and sensors/actuators
Hello Everyone,
We have a project at school (bachelor degrees) to develop a IoT system for external application (greenhouse, chicken coop,...).
We want to use an architecture with 3 layers :
- Cloud App with user frontend
- Central Unit (Rpi connected to the Internet) - Bridge between cloud and edge devices + administration
- Edge devices (ESP) with differents sensors/actuators
I am currently working on the esp side and looking to find the best way to preconfigure the ESP from the RPI. The idea is that the user have to connect the new ESP to the Rpi (by USB or Serial) to add it to the system. A new image will be compiled with correct Wifi and MQTT settings and flashed to the board.
I have already used EspEasy for previous projects and I would like to know if is it possible to configure the "devices" (sensors/actuators) from source files or by terminal ?
Best regards
Flo17
P.S. Sorry for spelling mystakes, english is not my mother tongue
We have a project at school (bachelor degrees) to develop a IoT system for external application (greenhouse, chicken coop,...).
We want to use an architecture with 3 layers :
- Cloud App with user frontend
- Central Unit (Rpi connected to the Internet) - Bridge between cloud and edge devices + administration
- Edge devices (ESP) with differents sensors/actuators
I am currently working on the esp side and looking to find the best way to preconfigure the ESP from the RPI. The idea is that the user have to connect the new ESP to the Rpi (by USB or Serial) to add it to the system. A new image will be compiled with correct Wifi and MQTT settings and flashed to the board.
I have already used EspEasy for previous projects and I would like to know if is it possible to configure the "devices" (sensors/actuators) from source files or by terminal ?
Best regards
Flo17
P.S. Sorry for spelling mystakes, english is not my mother tongue
Re: Build preconfigured ESP with MQTT and sensors/actuators
I've made a very basic attempt a while ago to add rules and some tasks depending on the chosen factory default setting.
But it is quite a lot of work to have it setup like that for all plugins.
Another approach is to let the files download from another host.
See the "settings archive": https://espeasy.readthedocs.io/en/lates ... gs-archive
It is not finished yet, but may help you think of possible options.
But it is quite a lot of work to have it setup like that for all plugins.
Another approach is to let the files download from another host.
See the "settings archive": https://espeasy.readthedocs.io/en/lates ... gs-archive
It is not finished yet, but may help you think of possible options.
Re: Build preconfigured ESP with MQTT and sensors/actuators
Thank you TD-er for your quick answer.
I can understand the complexity (specially with devices using multiples GPIO).
I don't think that the "settings archives" is a viable option, I would like to avoid the ("dummy") user to connect to the ESP.
In that case, I will certainly go for a homemade software.
I can understand the complexity (specially with devices using multiples GPIO).
I don't think that the "settings archives" is a viable option, I would like to avoid the ("dummy") user to connect to the ESP.
In that case, I will certainly go for a homemade software.
Re: Build preconfigured ESP with MQTT and sensors/actuators
Well, we could also extend the layers of authentication.
Now there is:
- No authentication
- Admin
When a password is set, you cannot change anything, but also a lot of view-only pages are inaccessible.
Maybe we also need some "operator" level, which could at most view values.
But it also needs some added layer for the commands then.
So instead of re-inventing the wheel, you could maybe also help in deciding what is needed to make it "classroom proof" ?
Now there is:
- No authentication
- Admin
When a password is set, you cannot change anything, but also a lot of view-only pages are inaccessible.
Maybe we also need some "operator" level, which could at most view values.
But it also needs some added layer for the commands then.
So instead of re-inventing the wheel, you could maybe also help in deciding what is needed to make it "classroom proof" ?
Re: Build preconfigured ESP with MQTT and sensors/actuators
From my view, it would be interesting having a "device" command with some parameters :
- device : id of the module to use (P001,P002,...)
name : name of the device
GPIO : array of GPIO needed by the device
Re: Build preconfigured ESP with MQTT and sensors/actuators
I take a look of the R120 source code. It seems that it should be possible to add a sensor by running a method with this line :
I took the parameters from the POST method
.
I will try to build this image on a ESP.
Code: Select all
Settings.TaskDeviceNumber[0] = 5;
tmpString = 'TestSensor'
strcpy(ExtraTaskSettings.TaskDeviceName, tmpString);
Settings.TaskDeviceTimer[0] = 0;
Settings.TaskDeviceID[0] = 0;
Settings.TaskDevicePin1[0] = 2;
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = 22;
Settings.TaskDeviceSendData = 1;
ExtraTaskSettings.TaskDeviceValueDecimals[1] = 2;
tmpString = ''
strcpy(ExtraTaskSettings.TaskDeviceFormula[1], tmpString);
ExtraTaskSettings.TaskDeviceValueDecimals[2] = 2;
tmpString = ''
strcpy(ExtraTaskSettings.TaskDeviceFormula[2], tmpString);
tmpString = 'Temperature'
strcpy(ExtraTaskSettings.TaskDeviceValueNames[1], tmpString);
tmpString = 'Humidity'
strcpy(ExtraTaskSettings.TaskDeviceValueNames[2], tmpString);
.
I will try to build this image on a ESP.
Re: Build preconfigured ESP with MQTT and sensors/actuators
R120 source code is about 2 years old now.
Maybe you could have a look at a bit more recent version?
I don't think the old code will compile with the current core versions.
Maybe you could have a look at a bit more recent version?
I don't think the old code will compile with the current core versions.
Re: Build preconfigured ESP with MQTT and sensors/actuators
Yeah you right, I get the source from the last release and will adapt it.
Re: Build preconfigured ESP with MQTT and sensors/actuators
I tried something like this,but I am getting a reboot when trying to access /devices
I think the isuee should be related to the ExtraTaskSettings (cannot call LoadTaskSettings method)
Code: Select all
void SetSensors()
{
byte taskIndex = 0;
char deviceName[] = "TestSensor";
unsigned long taskdevicetimer = 60;
bool enabled = true;
int pin1 = 2;
int pin2 = -1;
int pin3 = -1;
char deviceValue0[] = "Temperature";
char deviceFormula0[] = "";
int deviceValueDecimal0 = 2;
char deviceValue1[] = "Humidity";
int deviceValueDecimal1 = 2;
char deviceFormula1[] = "";
//LoadTaskSettings(taskIndex);
Settings.TaskDevicePluginConfig[taskIndex][0] = 22;
Settings.TaskDeviceNumber[taskIndex] = 5;
safe_strncpy(ExtraTaskSettings.TaskDeviceName, deviceName, sizeof(ExtraTaskSettings.TaskDeviceName));
Settings.TaskDeviceEnabled[taskIndex] = enabled;
if (taskdevicetimer > 0) {
Settings.TaskDeviceTimer[taskIndex] = taskdevicetimer;
} else {
Settings.TaskDeviceTimer[taskIndex] = 0;
}
if (pin1 >= 0) { Settings.TaskDevicePin1[taskIndex] = pin1; }
if (pin2 >= 0) { Settings.TaskDevicePin2[taskIndex] = pin2; }
if (pin3 >= 0) { Settings.TaskDevicePin3[taskIndex] = pin3; }
Settings.TaskDeviceSendData[0][0] = 1;
strcpy(ExtraTaskSettings.TaskDeviceValueNames[0], deviceValue0);
strcpy(ExtraTaskSettings.TaskDeviceFormula[0], deviceFormula0);
ExtraTaskSettings.TaskDeviceValueDecimals[1] = deviceValueDecimal0;
strcpy(ExtraTaskSettings.TaskDeviceValueNames[1], deviceValue1);
strcpy(ExtraTaskSettings.TaskDeviceFormula[1], deviceFormula1);
ExtraTaskSettings.TaskDeviceValueDecimals[1] = deviceValueDecimal1;
}
Re: Build preconfigured ESP with MQTT and sensors/actuators
Without calling LoadTaskSettings(taskIndex);
You will probably have the wrong extratasksettings active.
So changing it will corrupt the settings of another task (when saved)
Also I would not use char arrays like that.
Just to be sure, you can store them in a String object and call c_str() on the object.
You may also want to have a look at the F() macro, since having plain strings in the code will very quickly let you run out of memory.
You also made a typo here:
ExtraTaskSettings.TaskDeviceValueDecimals[1] = deviceValueDecimal0;
This is a list of controllers for the taskindex (2nd parameter) so you should iterate over it, or just call clearTask(taskindex) first.
Settings.TaskDeviceSendData[0][0] = 1;
You will probably have the wrong extratasksettings active.
So changing it will corrupt the settings of another task (when saved)
Also I would not use char arrays like that.
Just to be sure, you can store them in a String object and call c_str() on the object.
You may also want to have a look at the F() macro, since having plain strings in the code will very quickly let you run out of memory.
You also made a typo here:
ExtraTaskSettings.TaskDeviceValueDecimals[1] = deviceValueDecimal0;
This is a list of controllers for the taskindex (2nd parameter) so you should iterate over it, or just call clearTask(taskindex) first.
Settings.TaskDeviceSendData[0][0] = 1;
Who is online
Users browsing this forum: Ahrefs [Bot] and 31 guests