Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added plido-tp4/aiocoap/__pycache__/meta.cpython-314.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 9 additions & 7 deletions plido-tp4/coap_basic_server1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class TimeResource(resource.Resource):

async def render_get(self, request):
await asyncio.sleep(5)
# await asyncio.sleep(5)

payload = datetime.datetime.now().\
strftime("%Y-%m-%d %H:%M").encode('ascii')
Expand All @@ -35,7 +35,7 @@ async def render_get(self, request):
logging.basicConfig(level=logging.INFO)
logging.getLogger("coap-server").setLevel(logging.DEBUG)

def main():
async def main():
# Resource tree creation
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(("8.8.8.8", 80)) # connect outside to get local IP address
Expand All @@ -48,11 +48,13 @@ def main():

root.add_resource(['time'], TimeResource())

asyncio.Task(
aiocoap.Context.create_server_context(root,
bind=(ip_addr, port)))

asyncio.get_event_loop().run_forever()
await aiocoap.Context.create_server_context(root,bind=(ip_addr, port))

await asyncio.Future() # run forever

if __name__ == "__main__":
main()
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nServer stopped by user") #graceful exit on Ctrl+C
Binary file added pycom/__pycache__/CoAP.cpython-314.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion pycom/coap_empty_msg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CoAP
import socket

SERVER = "192.168.1.XX" # change to your server's IP address
SERVER = "192.168.11.109" # change to your server's IP address
PORT = 5683

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down
2 changes: 1 addition & 1 deletion pycom/coap_get_time1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CoAP
import socket

SERVER = "192.168.1.XX" # change to your server's IP address
SERVER = "192.168.11.109" # change to your server's IP address
PORT = 5683

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down
2 changes: 1 addition & 1 deletion pycom/coap_get_time2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CoAP
import socket

SERVER = "192.168.1.XX" # change to your server's IP address
SERVER = "192.168.11.109" # change to your server's IP address
PORT = 5683

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down
2 changes: 1 addition & 1 deletion pycom/coap_get_time3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CoAP
import socket

SERVER = "192.168.1.XX" # change to your server's IP address
SERVER = "192.168.11.109" # change to your server's IP address
PORT = 5683

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down
11 changes: 1 addition & 10 deletions pycom/coap_get_time4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CoAP
import socket

SERVER = "192.168.1.XX" # change to your server's IP address
SERVER = "192.168.11.109" # change to your server's IP address
PORT = 5683

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand All @@ -18,13 +18,4 @@
answer = CoAP.Message(resp)
answer.dump()

s.settimeout(10)
resp,addr = s.recvfrom(2000)
answer = CoAP.Message(resp)
answer.dump()

mid = answer.get_mid()
ack = CoAP.Message()
ack.new_header(mid=mid, type=CoAP.ACK)
ack.dump()
s.sendto (ack.to_byte(), (SERVER, PORT))
21 changes: 21 additions & 0 deletions pycom/coap_get_time_nonConf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import CoAP
import socket

SERVER = "192.168.11.109" # change to your server's IP address
PORT = 5683

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

coap = CoAP.Message()
coap.new_header(code=CoAP.GET,type=CoAP.NON , token=0x12345)
coap.add_option (CoAP.Uri_path, "time")
coap.dump()

s.sendto (coap.to_byte(), (SERVER, PORT))

s.settimeout(10)
resp,addr = s.recvfrom(2000)
answer = CoAP.Message(resp)
answer.dump()