ESP8266 Developer Zone The Official ESP8266 Forum 2016-05-16T14:51:10+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=2170 2016-05-16T14:51:10+08:00 2016-05-16T14:51:10+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2170&p=6914#p6914 <![CDATA[Re: Question About ESP mesh RSSI and Data]]>
yudxp wrote:
I have several question about ESP MESH DEMO

1. How i can increase range of ESP mesh? , because when i try it using esp-07 it only can receive data about max 17 meter. After ESP lost connection. And with only 50cm from router RSSI only read -50 is it normal? How i can achieve 100m range per hop like in your document?

2. Can i send data to ESP using demo_server.py? like to turn on and of Lamp etc. I am already try using chat socket server

Code:

#!/usr/bin/python
# chat_server.py
 
import sys
import socket
import select

HOST = ''
SOCKET_LIST = []
RECV_BUFFER = 1024
PORT = 7000

def chat_server():

    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind((HOST, PORT))
    server_socket.listen(10)
 
    # add server socket object to the list of readable connections
    SOCKET_LIST.append(server_socket)
 
    print "Chat server started on port " + str(PORT)
 
    while 1:

        # get the list sockets which are ready to be read through select
        # 4th arg, time_out  = 0 : poll and never block
        ready_to_read,ready_to_write,in_error = select.select(SOCKET_LIST,[],[],0)
     
        for sock in ready_to_read:
            # a new connection request recieved
            if sock == server_socket:
                sockfd, addr = server_socket.accept()
                SOCKET_LIST.append(sockfd)
                print "Client (%s, %s) connected" % addr
                 
                broadcast(server_socket, sockfd, "[%s:%s] entered our chatting room\n" % addr)
             
            # a message from a client, not a new connection
            else:
                # process data recieved from client,
                try:
                    # receiving data from the socket.
                    data = sock.recv(RECV_BUFFER)
                    if data:
                        #print >>sys.stderr, 'Header "%s"' % binascii.hexlify(data[0:4])
                        broadcast(server_socket, sock,data)
                    else:
                        # remove the socket that's broken   
                        if sock in SOCKET_LIST:
                            SOCKET_LIST.remove(sock)

                        # at this stage, no data means probably the connection has been broken
                        broadcast(server_socket, sock, "Client (%s, %s) is offline\n" % addr)

                # exception
                except:
                    broadcast(server_socket, sock, "Client (%s, %s) is offline\n" % addr)
                    continue

    server_socket.close()
   
# broadcast chat messages to all connected clients
def broadcast (server_socket, sock, message):
    for socket in SOCKET_LIST:
        # send the message only to peer
        if socket != server_socket and socket != sock :
            try :
                socket.send(message)
            except :
                # broken socket connection
                socket.close()
                # broken socket, remove it
                if socket in SOCKET_LIST:
                    SOCKET_LIST.remove(socket)
 
if __name__ == "__main__":

    sys.exit(chat_server())         


and client to send data

Code:

# chat_client.py
#!/usr/bin/python

import sys
import socket
import select
import binascii

def chat_client():
    if(len(sys.argv) < 3) :
        print 'Usage : python chat_client.py hostname port'
        sys.exit()

    host = sys.argv[1]
    port = int(sys.argv[2])
     
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(2)
     
    # connect to remote host
    try :
        s.connect((host, port))
    except :
        print 'Unable to connect'
        sys.exit()
     
    print 'Connected to remote host. You can start sending messages'
    sys.stdout.write('[Me] '); sys.stdout.flush()
     
    while 1:
        socket_list = [sys.stdin, s]
         
        # Get the list sockets which are readable
        ready_to_read,ready_to_write,in_error = select.select(socket_list , [], [])
         
        for sock in ready_to_read:             
            if sock == s:
                # incoming message from remote server, s
                data = sock.recv(1024)
                if not data :
                    print '\nDisconnected from chat server'
                    sys.exit()
                else :
                    #print data
                    sys.stdout.write(data)
                    sys.stdout.write('[Me] '); sys.stdout.flush()     
           
            else :
                # user entered a message
                msg = sys.stdin.readline()
                data = str(msg).split('/')
                print data
                test = bytearray()
                test[0:4]= binascii.unhexlify(data[0])
                test[4:10]= binascii.unhexlify(data[1])
                test[10:16]= binascii.unhexlify(data[2])
                test[16:]= data[3]
                data_sent = test[0:4] + test[4:10]+ test[10:16]+ test[16:]
                print 'Payload: ' + binascii.hexlify(data_sent[0:])
                s.send(data_sent)
                sys.stdout.write('[Me] '); sys.stdout.flush()

if __name__ == "__main__":

    sys.exit(chat_client())


and try send data like in demo_server.py that included : Header + Source + Target + Payload and still no luck.

thx for your help

Yudha


1. Something about RSSI, please visit Technical support.
2. Please build packet according the mesh packet format, you can get document from github:
https://github.com/espressif/ESP8266_ME ... r/document

Statistics: Posted by Guest — Mon May 16, 2016 2:51 pm


]]>
2016-05-13T20:33:18+08:00 2016-05-13T20:33:18+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2170&p=6892#p6892 <![CDATA[Question About ESP mesh RSSI and Data]]>
1. How i can increase range of ESP mesh? , because when i try it using esp-07 it only can receive data about max 17 meter. After ESP lost connection. And with only 50cm from router RSSI only read -50 is it normal? How i can achieve 100m range per hop like in your document?

2. Can i send data to ESP using demo_server.py? like to turn on and of Lamp etc. I am already try using chat socket server

Code:

#!/usr/bin/python
# chat_server.py
 
import sys
import socket
import select

HOST = ''
SOCKET_LIST = []
RECV_BUFFER = 1024
PORT = 7000

def chat_server():

    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind((HOST, PORT))
    server_socket.listen(10)
 
    # add server socket object to the list of readable connections
    SOCKET_LIST.append(server_socket)
 
    print "Chat server started on port " + str(PORT)
 
    while 1:

        # get the list sockets which are ready to be read through select
        # 4th arg, time_out  = 0 : poll and never block
        ready_to_read,ready_to_write,in_error = select.select(SOCKET_LIST,[],[],0)
     
        for sock in ready_to_read:
            # a new connection request recieved
            if sock == server_socket:
                sockfd, addr = server_socket.accept()
                SOCKET_LIST.append(sockfd)
                print "Client (%s, %s) connected" % addr
                 
                broadcast(server_socket, sockfd, "[%s:%s] entered our chatting room\n" % addr)
             
            # a message from a client, not a new connection
            else:
                # process data recieved from client,
                try:
                    # receiving data from the socket.
                    data = sock.recv(RECV_BUFFER)
                    if data:
                        #print >>sys.stderr, 'Header "%s"' % binascii.hexlify(data[0:4])
                        broadcast(server_socket, sock,data)
                    else:
                        # remove the socket that's broken   
                        if sock in SOCKET_LIST:
                            SOCKET_LIST.remove(sock)

                        # at this stage, no data means probably the connection has been broken
                        broadcast(server_socket, sock, "Client (%s, %s) is offline\n" % addr)

                # exception
                except:
                    broadcast(server_socket, sock, "Client (%s, %s) is offline\n" % addr)
                    continue

    server_socket.close()
   
# broadcast chat messages to all connected clients
def broadcast (server_socket, sock, message):
    for socket in SOCKET_LIST:
        # send the message only to peer
        if socket != server_socket and socket != sock :
            try :
                socket.send(message)
            except :
                # broken socket connection
                socket.close()
                # broken socket, remove it
                if socket in SOCKET_LIST:
                    SOCKET_LIST.remove(socket)
 
if __name__ == "__main__":

    sys.exit(chat_server())         


and client to send data

Code:

# chat_client.py
#!/usr/bin/python

import sys
import socket
import select
import binascii

def chat_client():
    if(len(sys.argv) < 3) :
        print 'Usage : python chat_client.py hostname port'
        sys.exit()

    host = sys.argv[1]
    port = int(sys.argv[2])
     
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(2)
     
    # connect to remote host
    try :
        s.connect((host, port))
    except :
        print 'Unable to connect'
        sys.exit()
     
    print 'Connected to remote host. You can start sending messages'
    sys.stdout.write('[Me] '); sys.stdout.flush()
     
    while 1:
        socket_list = [sys.stdin, s]
         
        # Get the list sockets which are readable
        ready_to_read,ready_to_write,in_error = select.select(socket_list , [], [])
         
        for sock in ready_to_read:             
            if sock == s:
                # incoming message from remote server, s
                data = sock.recv(1024)
                if not data :
                    print '\nDisconnected from chat server'
                    sys.exit()
                else :
                    #print data
                    sys.stdout.write(data)
                    sys.stdout.write('[Me] '); sys.stdout.flush()     
           
            else :
                # user entered a message
                msg = sys.stdin.readline()
                data = str(msg).split('/')
                print data
                test = bytearray()
                test[0:4]= binascii.unhexlify(data[0])
                test[4:10]= binascii.unhexlify(data[1])
                test[10:16]= binascii.unhexlify(data[2])
                test[16:]= data[3]
                data_sent = test[0:4] + test[4:10]+ test[10:16]+ test[16:]
                print 'Payload: ' + binascii.hexlify(data_sent[0:])
                s.send(data_sent)
                sys.stdout.write('[Me] '); sys.stdout.flush()

if __name__ == "__main__":

    sys.exit(chat_client())


and try send data like in demo_server.py that included : Header + Source + Target + Payload and still no luck.

thx for your help

Yudha

Statistics: Posted by yudxp — Fri May 13, 2016 8:33 pm


]]>