logo elektroda
logo elektroda
X
logo elektroda

Best way to transmit data between two ESP8266-12 modules: UDP or TCP for sensors?

przemas314 4098 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 15597988
    przemas314
    Level 9  
    Welcome,

    First of all, I would like to inform that I am a person just starting my adventure with ESP8266-12 module.
    So, I'm planning to create a smart lighting system for a corridor, if someone enters the room, the first sensor detects movement - the first lamp will light up, when they reach the second one, the next sensor detects movement - the first one must go out and the second one will light up.
    The whole system is to consist of two ESP modules and a motion sensor and relay connected to each.
    What is the easiest way to program the modules to transmit data between them? Should it be via UDP? TCP?
    Please help
  • ADVERTISEMENT
  • #2 15606393
    @Kamil
    Level 23  
    Hello,
    I had the same dilemma recently, I even asked a few posts below.
    Today I'm a bit wiser now. The easiest way to communicate is via UDP. I decided to use the Arduino IDE, and although I had no previous experience with it I quickly got to grips with it.
    There is one very good example of a UDP server, unfortunately I don't know if I can paste it here, but it's easy to find on google.
    Regards
  • ADVERTISEMENT
  • #3 15606428
    przemas314
    Level 9  
    Thank you for your help, can you send me this example by email: przemo.dud(_at_)gmail.com
  • ADVERTISEMENT
  • Helpful post
    #4 15609520
    piotr411
    Level 22  
    In Basic ESP it will be like this:

    "Transmitter"

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


    "Receiver:"
    Code: VB.net
    Log in, to see the code
  • ADVERTISEMENT
  • #5 15610712
    przemas314
    Level 9  
    In my project all the modules have to transmit data between each other, it seems to me that one cannot be the transmitter and the other the receiver but one and the other must be the transmitter and the receiver. I have tested one example of UDP communication but I can only send text messages from one to the other, I can't find anywhere an example of how to e.g. send data from one module so that an LED lights up on the other. Please help
  • Helpful post
    #6 15610860
    piotr411
    Level 22  
    each ESP has a unique IDChip number. by this number you can attach or transmit data sequentially. It's a very simple algorithm.
  • #7 15610951
    przemas314
    Level 9  
    And how can this chipID be checked/calculated? Is it written in the module documentation somewhere? Or is it simply a GPIO?
  • Helpful post
    #8 15611092
    piotr411
    Level 22  
    In Basic this is the command - id()
    In LUA it is - node.chipid()
    In C it will be ESP.getChipId()

    In C will be the most writing, personally I prefer to write in LUA, or Basic. Although because of the ready-made libraries I use Arduino. I have to admit that I don't like this environment very much, and the plugin for ESP doesn't work for me in Atmel Studio.
  • #9 15612541
    przemas314
    Level 9  
    And could someone give me an example of such an algorithm?
  • #10 15614735
    piotr411
    Level 22  
    Code: Lua
    Log in, to see the code


    Show a diagram of what you have done, only then can you put together a program. Write in which language you want to write it, from my side I can help in C, Basic, LUA
ADVERTISEMENT