logo elektroda
logo elektroda
X

Bascom - Atmega1284P + ESP8266 + Domoticz - random JSON data sending

maximus22_kr 2457 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16726784
    maximus22_kr
    Level 18  
    I have a circuit with the configuration as in the title ( to which DS sensors, BME280, SD recording, RFM12 )

    The last step is to send via JSON to Domoticz. Unfortunately the sending fails and does it randomly, sometimes after sending data from several sensors, sometimes it will go through the whole "cycle"
    The interval between sending is between 20 and 30 seconds, while the interval between sending data for a specific sensor is 11 minutes.
    The whole code is attached, I paste only the part responsible for Domoticz + the Select Case fragment. For the reception of the UART, I used Serial0charmatch according to Niveasoft's idea.
    Code: VB.net
    Log in, to see the code
    .

    And now connecting to the UART from the Tx side of the ESP8266 I have:
    Code: Bash
    Log in, to see the code
    .

    It looks like the Atmega stops responding to the "OK" response - to the AT+PING="192.168.0.92" command. The ESP8266 is unlikely to be at fault - it sends back "OK" and the Atmega should start sending at that point. I reset it while it was running, this didn't change anything, only a reset of the whole chip helps - for a while.

    In addition, as a "bonus" ( but this requires a look at the code ) up to the moment when sending to Domoticz still works, communication with Master 2 does not work, at the moment when sensor data is no longer sent to Domoticz, receiving data from Master 2 starts to work as it should. And, of course, apart from this problem, the whole thing works - whether data is sent or not - reading sensors, sending to clients and writing to SD - it all works.

    What could be the reason for this behaviour of the Atmega UART ?
  • ADVERTISEMENT
  • #2 16734452
    maximus22_kr
    Level 18  
    I converted the program to Atmega328. Now it just has to receive data from the master on the Atega1284p and send to Domoticz.
    Code: VB.net
    Log in, to see the code
    .

    I also changed the IP address where it sends the PING to 8.8.8.8

    But nothing has changed. Sometimes a "+timeout" pops up
    Code: Bash
    Log in, to see the code
    .


    Maybe Domoticz itself ( installed on Orange PI Zero ) is doing some problems ? Maybe I am updating too often ?
    I guess it will come to wait for someone smarter to brag about their achievements.
  • ADVERTISEMENT
  • #3 16740484
    maximus22_kr
    Level 18  
    Eventually I send to Domoticz like this:
    Code: VB.net
    Log in, to see the code
    .

    It works, but only once after a power on/reset.
    Maybe someone can suggest what is wrong ? The only idea is that the UART is not handled properly. Maybe you need to throw away that extra flag Domoticz_en , just in the first Case of the Domoticz_send subroutine to parse it ?
  • ADVERTISEMENT
  • #4 16740518
    Anonymous
    Anonymous  
  • #5 16742173
    maximus22_kr
    Level 18  
    I know and use the other UART, even just to know where the program is.
    But it seemed to me that plugging in the Tx of the ESP8266 would make the most sense.
    RealTerm showed the CrLF characters
    Code: Bash
    Log in, to see the code
    .

    Note that the first time is fine - it passes all 28 entries. Maybe the ESP8266 is sending something and this is "clogging up" the UART. So far RealTerm is only showing CrLf characters after CLOSED

    Code: Bash
    Log in, to see the code
    .
  • #6 16742299
    Anonymous
    Anonymous  
  • ADVERTISEMENT
  • #7 16745740
    maximus22_kr
    Level 18  
    If you have the ability to do so, that would be great. As you can see the Atmega is behaving strangely. As if it doesn't work at all I would look for the problem in the code.
    It's not likely a hardware problem, the operating conditions don't change.
  • #8 16746030
    Anonymous
    Anonymous  
  • #9 16746056
    maximus22_kr
    Level 18  
    Well it's Orange Pi Zero easier, all you need is a terminal set to 115200 and Putty, to start with I was connecting via terminal, now I'm connecting via SSH.
    I've done a little bit of work with it, i.e. activated the ports, tried to control them from Python, installed a server with PHP 5, MySql, Apache 2.

    The Orange Pi Zero doesn't have HDMI, only composite I think.
    Even a DUC program to communicate with the Noip - except that something doesn't work Noip - I can see the address from the Noip on the local computers, i.e. I either type in the IP or the address from the Noip and it works, but externally it doesn't work - I even ventured a topic on the forum.
  • #10 16753938
    maximus22_kr
    Level 18  
    Unfortunately today I had to change my router for a TP-Link TD-W8970 ( I just had one )
    The result is that even after a reset it does not send - it is as follows
    Code: Bash
    Log in, to see the code
    .

    Maybe some router setting is causing the problem.
  • #11 16757769
    maximus22_kr
    Level 18  
    I have converted it so that it only sends a test value ( random ) every 8 seconds

    Code: VB.net
    Log in, to see the code


    there is a problem with receiving from ESP

    Communication with tx ESP:
    Code: Bash
    Log in, to see the code
    .

    After AT ( or after Ping, depends how I initiate ) the module does not send OK. Then after the connection it does not answer CONNECT, so it is probably about the answer "Link is not valid".

    Added after 18 [hours] 29 [minutes]: .

    I added
    Clear Serialin0
    Com1_str = ""

    i.e.
    Code: VB.net
    Log in, to see the code


    and it works. I'm going to try to adjust this for bulk shipping.
  • #12 16765366
    maximus22_kr
    Level 18  
    The final result looks like this:
    Code: VB.net
    Log in, to see the code
    .

    Admittedly, after several hours of operation, sometimes only the first sent record arrives ( but only the first one ) intermittently ( interestingly there are entries in the database but with the last received value ). I need to hook it up to the UART and see what happens.
  • #13 17906531
    marcosx
    Level 12  
    Hello
    This is how I read it today, and I don't know if you have solved the problem.
    But I don't see anywhere in the code the command AT+CIPCLOSE=5
    and it is needed for the ESP8266 to work properly
    maybe I'm wrong.
    Greetings Marian

Topic summary

The discussion centers on integrating an Atmega1284P microcontroller with an ESP8266 Wi-Fi module to send sensor data via JSON to the Domoticz home automation system. The original setup included multiple sensors (DS sensors, BME280), SD card recording, and RFM12 communication. The main issue was intermittent failure in sending JSON data to Domoticz, with irregular success in completing full data cycles. The user experimented with converting the code to run on an Atmega328P for simpler testing and focused on UART communication configurations, using Serial0charmatch for UART reception. Challenges included handling ESP8266 prompts and responses, managing UART buffers, and ensuring proper TCP connection handling. Router changes (to a TP-Link TD-W8970) introduced additional connectivity problems, such as "link is not valid" errors during AT command sequences. Suggestions included using a microcontroller with multiple USARTs for better debugging, monitoring ESP8266 responses carefully, and ensuring proper AT command sequences including connection closure commands like AT+CIPCLOSE. The user also explored alternative hardware like Raspberry Pi and Orange Pi Zero for network interfacing and testing Domoticz. The final code iterations focused on sending simplified test JSON data at regular intervals to isolate the problem. The discussion highlights the complexity of reliable UART communication with ESP8266 modules, the importance of handling asynchronous prompts, and the impact of network hardware on TCP communication stability.
Summary generated by the language model.
ADVERTISEMENT