@franz-unix it really an overkill... you can use gpio from esp to control pan and tilt no need for atmega and nrf...
Mickey
Posts
-
Esp32-cam with pan - Mysensors powered -
Cheap dirty way to send a raw-mysensors message?@cimba007
Can you post the complete code of the chirp including the headers?
Did you only include these libraries:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
? -
GatewayESP8266MQTTClient with realtime connection paramsIs the
"bcn_timout,ap_probe_send_start
ap_probe_send over, rest wifi status to disassoc"message is a known issue? I cant seem to find anything with this string when searching this forum...
-
GatewayESP8266MQTTClient with realtime connection paramsSo after seeing this post:
https://forum.mysensors.org/topic/5533/esp8266-gw-node-mqtt-transport-won-t-present-sketch-or-actuator-to-controllerI finally succeeded to change the GatewayESP8266MQTTClient that it can load connection parameters dynamicaly and also use smart config to send SSID and password to the ESP.(I using a android app I developped for it).
This is the source code of GatewayESP8266MQTTClient:#include <EEPROM.h> #include <SPI.h> #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> #include <ArduinoJson.h> #include <FS.h> const int button = 0;//button for reset config ESP8266WebServer server (80); File configFile; boolean configExist = false; struct My_Config_t { String WLAN_STA_SSID = ""; String WLAN_STA_PASSWD = ""; String MQTT_Broker_FQDN = ""; //IPAddress MQTT_Broker_IP; uint16_t MQTT_Broker_Port = 0; } My_Config; // Enable debug prints to serial monitor #define MY_DEBUG //#define MY_DEBUG_VERBOSE //#define TRANSPORT_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_ESP8266 // Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in" // Set MQTT client id #define MY_MQTT_CLIENT_ID "mysensors-1" // Enable these if your MQTT broker requires usenrame/password //#define MY_MQTT_USER "username" //#define MY_MQTT_PASSWORD "password" // Set WIFI SSID and password #define MY_ESP8266_SSID (My_Config.WLAN_STA_SSID).c_str() #define MY_ESP8266_PASSWORD (My_Config.WLAN_STA_PASSWD).c_str() // MQTT broker ip address. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 //#define MY_CONTROLLER_URL_ADDRESS "test.mosquitto.org" #define MY_CONTROLLER_URL_ADDRESS ((My_Config.MQTT_Broker_FQDN).c_str()) // The MQTT broker port to to open //#define MY_PORT 1883 #define MY_PORT (My_Config.MQTT_Broker_Port) bool loadConfig() { configFile = SPIFFS.open("/config.json", "r"); if (!configFile) { 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]); configFile.readBytes(buf.get(), size); StaticJsonBuffer<1024> jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); if (!json.success()) { Serial.println("Failed to parse config file"); return false; } char MQTTURL[40]; char MQTTPORT[4]; char wlan_sta_ssid[20]; char wlan_sta_passwd[20]; strcpy(wlan_sta_ssid, json["wlan_sta_ssid"]); strcpy(wlan_sta_passwd, json["wlan_sta_passwd"]); strcpy(MQTTURL, json["mqttbrockerurl"]); strcpy(MQTTPORT, json["mqttport"]); My_Config.WLAN_STA_SSID = String(wlan_sta_ssid); My_Config.WLAN_STA_PASSWD = String(wlan_sta_passwd); My_Config.MQTT_Broker_FQDN = String(MQTTURL); My_Config.MQTT_Broker_Port = String(MQTTPORT).toInt(); configFile.close(); jsonBuffer = StaticJsonBuffer<1024>(); return true; } bool startSmartConfig() { WiFi.mode(WIFI_STA); delay(500); // Start SmartConfig if necessary WiFi.beginSmartConfig(); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if(WiFi.smartConfigDone()) Serial.println("smart Config Done"); } WiFi.stopSmartConfig(); delay(500); WiFi.begin(); return true; } void handleJson() { StaticJsonBuffer<1024> newBuffer; JsonObject& newjson = newBuffer.parseObject(server.arg("plain")); server.sendHeader("Access-Control-Max-Age", "10000"); server.sendHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS"); server.sendHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); if (!newjson.success()) { Serial.println("Failed to parse config file from handleJson 1"); server.send ( 200, "text/json", "{success:false,deviceID:'none'}" ); } else{ configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { Serial.println("Failed to open config file for writing in handleJson 2"); server.send ( 200, "text/json", "{success:false,deviceID:'none'}" ); } else{ newjson.printTo(configFile); configFile.close(); //server.send ( 200, "text/json", "{success:true,deviceID:'bla'}" );*/ server.send ( 200, "text/json", "{ \"success\": \"OK\",\"deviceID\": \""+String(MY_MQTT_CLIENT_ID)+"\" }" ); newBuffer = StaticJsonBuffer<1024>(); } } } void startConfigWebServer() { server.on("/json",handleJson); server.begin(); // Web server start Serial.println("HTTP server started"); } #include <MySensors.h> void before() { Serial.println("Resetting WiFi credentials"); WiFi.disconnect(); ESP.eraseConfig(); //spi_flash_erase_sector(0x7e); if (!SPIFFS.begin()) { Serial.println("Failed to mount file system"); } if(!loadConfig()) { if(startSmartConfig()) { startConfigWebServer(); server.handleClient(); } while(!loadConfig()) { server.handleClient(); } delay(2000); server.stop(); WiFi.disconnect(); ESP.eraseConfig(); // spi_flash_erase_sector(0x7e); //loadConfig(); SPIFFS.end(); ESP.reset(); } else{Serial.println("Config loaded..."); delay(2000); } server.stop(); WiFi.disconnect(); ESP.eraseConfig(); // spi_flash_erase_sector(0x7e); //loadConfig(); SPIFFS.end(); //ESP.reset(); } void setup() { ESP.wdtDisable(); pinMode( button, INPUT_PULLUP ); digitalRead(button) == HIGH; } void presentation() { // Present locally attached sensors here } void loop() { ESP.wdtDisable(); //Serial.println("inside loop"); if ( digitalRead(button) == LOW ) { Serial.println("Resetting WiFi credentials"); SPIFFS.begin(); SPIFFS.remove("/config.json"); SPIFFS.end(); WiFi.disconnect(); ESP.eraseConfig(); spi_flash_erase_sector(0x7e); configExist = false; ESP.restart(); } //Send locally attech sensors data here }So after a some time I get this esp reset (I tried to put ESP.wdtDisable(); in loop)
this is the serial output:connected with MYSSID, channel 1 dhcp client start... ..ip:192.168.0.113,mask:255.255.255.0,gw:192.168.0.1 .IP: 192.168.0.113 0;255;3;0;9;MCO:BGN:STP 0;255;3;0;9;MCO:BGN:INIT OK,TSP=1 IP: 192.168.0.113 0;255;3;0;9;Attempting MQTT connection... 0;255;3;0;9;MQTT connected 0;255;3;0;9;Sending message on topic: mygateway1-out/0/255/0/0/18 pm open,type:2 0but after a few seconds (mainly after a message is sent from a sensor...but not only . if I send a message from broker that is not sending via radio to sensor its more stable ) I getting this:
bcn_timout,ap_probe_send_start ap_probe_send over, rest wifi status to disassoc state: 5 -> 0 (1) rm 0 pm close 7 ?)�L®D‚And its seems that the ESP is resetting itself...
What do you think I can do to make this more stable? maybe add "__yield" some where? (I think to adding of ESP.wdtDisable helped a little at list the reset is with out the long stack message...) -
ESP8266 GW+Node (MQTT Transport): Won't Present Sketch or Actuator To Controller@non_avg_joe
In the section where needed to populate the params from SPIFFS// Here to be the reading of a json/cbor object from a file on a local storage (e.g. : SPIFFS over Serial NVRAM) & the parsing of it into the My_Config struct My_Config.WLAN_STA_SSID = "My-WLAN"; My_Config.WLAN_STA_PASSWD = "My-Passwd"; My_Config.MQTT_Broker_FQDN = "hercules.local";Did you ever got to implement this section?
-
Gateway to hands out node ID'sSo I went and change the MyTransport.cpp file and added a few lines around line 740:
uint8_t currentID; #if defined(MY_GATEWAY_FEATURE) if (type == I_ID_REQUEST) { currentID = hwReadConfig(0X123); //Read first byte of free conf eeprom space if(currentID==0xFF)//check to see if it was never changed (255)... {currentID = 1;} _msg.set(currentID); if(transportSendWrite(0xFF,_msg)) { hwWriteConfig(0X123,currentID+1) } } else // Hand over message to controllerBut the sensor still requesting an ID without getting it...
-
Gateway to hands out node ID's@hek said:
Why pass it to the sketch? You could implement the id-handout directly in core (I pointed out the area where internal messages directed to the node is processed).
To mess with core as little as I could so it can be easy upgradable in future (I already altered the MyGatewayTransportMQTTClient.cpp to support using dynamic connection parameters instead hard coded , I don't want to alter a lot of core files but if it necessary I will...)
-
Gateway to hands out node ID's@hek said:
Internal messages does not get exposed in the receive() function of the sketch.
To archive this you would have to modify the core somewhere here:
https://github.com/mysensors/MySensors/blob/development/core/MyTransport.cpp#L706Thanks for answer.
I tried to figure where I change the internal msg type to be exposed to GW in the MyTransport.cpp around line 706 but can't seems to find it... -
Gateway to hands out node ID's@sundberg84 it's need to be automatic. Fix id is easy to implement but because there will be an unknown number of nodes than I cannot use fix id's...
-
Gateway to hands out node ID's@tbowmo said:
This is not implemented in the gateway code, as it's "always" been the job of the attached controller.
I know it's "always" been the job of the attached controller but I have a scenario that the mqtt gateway will send directly to a cloud broker and an app that will receive it without any controller on the way. one problem I facing is the nodes id handing...so my question is if I would like to implement this in the GatewayESP8266MQTTClient.ino file is it possible?(check for incoming id request and 255 id number and saving current id handed in gateway eeprom etc...)
-
Gateway to hands out node ID'sHi
Is it even possible to implement that Gateway will hands out node ID's ?(something simple like store the assigned id's in eeprom and hand out what is not assigned...) -
GatewayESP8266MQTTClient with realtime connection paramsSo I saw that I cannot use WIFI object out side setup and also if I take all the web based parameters configuration code to a separate library its not so different because library initiation can be done only in setup function also.
So I'm trying to include an ordinary cpp code that will perform this before #include <MySensors.h> and before setup. So how do I go and do that should I include the cpp file in the ino file or do I do it like an ordinary library and only include the .h file?Also I had another problem
@hek said:strcpy(myTopicPrefix, <something>);
So if I implement this code :
String uniqueID = (String)ESP.getChipId(); #define MY_MQTT_CLIENT_ID uniqueID char mqtt_username[20]; char mqtt_password[20]; strcpy(mqtt_username, json["mqttusername"]); strcpy(mqtt_password, json["mqttpassword"]); #define MY_MQTT_USER mqtt_username #define MY_MQTT_PASSWORD mqtt_passwordI keep getting this error: error: no matching function for call to 'PubSubClient::connect(String&, char [20], char [20])' candidates are: boolean PubSubClient::connect(const char*, const char*, const char*)Is it mean that I can only use const variables and thus cannot put dynamic parameters that I will get from user at run time?
***EDIT
I finally change the MyGatewayTransportMQTTClient.cpp without really touching the ino file... -
GatewayESP8266MQTTClient with realtime connection paramsI included whats need to be included and this variable known when it is inside setup function but I need to call it before setup().
EDIT
@hek I trying to implement your suggested pseudo code but in an ordinary esp8266 sketch WIFI object is only recognizable in the setup function and on but in the GatewayESP8266MQTTClient.ino the setup is empty and the WIFI object becoming recognizable somewhere in the core code long before the main sketch setup function.
I see that it is put to use already in MyGatewayTransportMQTTClient.cpp and MyGatewayTransportEthernet.cpp but in order to receive the mqtt params from user I need to use the WIFI object before including MySensors (#include <MySensors.h>) much like it is being done by the core.(to use the WIFI object it is not enough to include <ESP8266WiFi.h> but also to initiate it in setup).So how it is done in the core? what one need to include/implement in order to use WIFI in the GatewayESP8266MQTTClient.ino before including <MySensors.h> and before the setup function.
Hope I made myself clear enough ...
thanks -
GatewayESP8266MQTTClient with realtime connection paramsHi
So I change the order of the core code as I mention and all the WIFI connection is done before the main sketch setup function instead off the MyGatewayTransportMQTTClient.cpp file.
But when I try to use:
WiFi.mode(WIFI_STA);
or
WiFi.hostname(MY_ESP8266_HOSTNAME);
or
WiFi.begin();
before the setup function I keep getting:
error: 'WiFi' does not name a type.
Can I take WIFI.begin() before setup ? (the original core code seems to do it... ) -
GatewayESP8266MQTTClient with realtime connection paramsHi
I would like to alter GatewayESP8266MQTTClient.ino a bit to be able to transfer mqtt broker connection params from an HTML5 app I developed.
I altered the core code in the file MyGatewayTransportMQTTClient.cpp to enable SMARTCONFIG:
WiFi.beginSmartConfig();
To be able to transfer the SSID and PASS dynamically from the app.All the other params(server IP, user/password for MQTT broker etc.) I would send from the app with JSON and the GATEWAY will save them to local storage (the ESP-12 have 4mb for storage).
I do not want to alter core files too much and would like to implement all of the above in the ino file as much as I can.(with the smart config option I didn't see a way other than altering the MyGatewayTransportMQTTClient file.)The MyGatewayTransportMQTTClient file looks for defined variables to function but I need to change the code to enable dynamic params.
The parameters I need to change are:
#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in" #define MY_MQTT_CLIENT_ID "mysensors-1" #define MY_MQTT_USER "username" #define MY_MQTT_PASSWORD "password" #define MY_ESP8266_SSID "MySSID" #define MY_ESP8266_PASSWORD "MyVerySecretPassword" #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway" #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 #define MY_PORT 1883I know how to code the ino file to listen to JSON and then process the data and put it in storage but I cant seem to grasp how to change the core file as minimally as I can...
-
MYSBootloader 1.3 pre-release & MYSController 1.0.0beta -
MYSBootloader 1.4 testingHi
I would like to test too.
On atmega 328p au 8mhz internal board. -
MYSBootloader 1.3 pre-release & MYSController 1.0.0beta@tekka
It's not failing the node is functional and I can upload a sketch to it via MYSController but It cannot get sketch from the arduino IDE (the IDE gives the normal output that upload complete and all OK without any Error notice but after it the node doesn't have a FW on it and even if I upload some basic sketch that spit Serial to monitor nothing happen.)
I will try to upload the bootloader to an Arduino nano node to see if on 16Mhz board and 115200bps the problem exist.
Also you mention that the hex file compiled to 16Mhz board and 115200bps , maybe it should also compile on a internal 8Mhz to fix this. -
MYSBootloader 1.3 pre-release & MYSController 1.0.0beta@tekka
My arduino IDE: 1.6.11
The avrdude inside that arduino IDE is: 6.0.1 -
MYSBootloader 1.3 pre-release & MYSController 1.0.0beta@tekka
I used the MYSBootloader 1.3pre with version 2.0.0
I managed to upload FW to nodes with MYSController.As mention:
"supports OTA FW AND serial FW updates"But I cannot get anything to serial port with the nodes.
Is the serial option really works on this bootloader?
the specs:
1.board - my own developed board with atmega328p au without external clock.
2.board.txt:######## settings for 8Mhz internal clock, EESAVE, BOD1V8, no lock proMYSBL8.name=ATmega328 internal 8Mhz with MYSBootloader proMYSBL8.upload.tool=avrdude proMYSBL8.upload.protocol=arduino proMYSBL8.upload.maximum_size=30720 proMYSBL8.upload.maximum_data_size=2048 proMYSBL8.upload.speed=57600 proMYSBL8.bootloader.tool=avrdude proMYSBL8.bootloader.low_fuses=0xE2 proMYSBL8.bootloader.high_fuses=0xD2 proMYSBL8.bootloader.extended_fuses=0x06 proMYSBL8.bootloader.unlock_bits=0x3F proMYSBL8.bootloader.lock_bits=0x3F proMYSBL8.bootloader.file=MySensors/MYSBootloaderV13pre.hex proMYSBL8.build.mcu=atmega328p proMYSBL8.build.f_cpu=8000000L proMYSBL8.build.board=AVR_UNO proMYSBL8.build.core=arduino proMYSBL8.build.variant=standard- the bootloader hex file is : MYSBootloaderV13pre.hex from MYSController 1.0.0beta
So is serial possible or/and should I change something?