Enc28j60 TCP Socket connection problem
Hi, I try to send and record temperature value to computer for a few days. Server software was writen using python and it was tested with client software from another computer (no firewall). I had no success
Before, I used the same circuit to connect a smtp server. it sent mail with similiar code. I'm sure the circuit works. Same code that is for mail, didn't provide a connection my computer and my server software.
Can anyone explain the mistake?
Server software
Before, I used the same circuit to connect a smtp server. it sent mail with similiar code. I'm sure the circuit works. Same code that is for mail, didn't provide a connection my computer and my server software.
Can anyone explain the mistake?
CON
_clkmode = xtal1+pll16x
_xinfreq = 5_000_000
BufferSize = 4096
MAX_DEVICES = 8
OBJ
sock : "api_telnet_serial"
key : "Keyboard"
tv : "tv_text"
VAR
long hararetStack[32]
long sockbag[64]
long size
byte webBuffer[BufferSize]
byte tem
byte fname[13]
byte extension[4]
long type
long sicaklik
long addrs[2 * MAX_DEVICES]
long myServerIP
word myServerPort
word myHostPort
DAT
mac_addr byte $10, $00, $00, $00, $00, $01
ip_addr byte 10, 0, 3, 16
ip_subnet byte 255, 255, 255, 0
ip_gateway byte 10, 0, 3, 2
ip_dns byte 10, 0, 3, 2
ip_serv byte 10, 0, 3, 11
port_serv byte 3422
port_host byte 5433
PUB start
key.start(26,27)
tv.start(12)
sock.start(8,9,10,11,-1,-1,@mac_addr,@ip_addr)
cognew(serverbaglan, @sockbag)
tv.str(string("Basladi"))
PUB serverbaglan
myServerIP:= (byte[@ip_serv]<<24)+(byte[@ip_serv+1]<<16)+(byte[@ip_serv+2]<<8)+byte[@ip_serv+3]
myServerPort:= byte[@port_serv]
myHostPort:= byte[@port_host]
repeat 3
key.getkey
MyClient
PUB MyClient
tv.str(string("Haydi "))
dira[20]~~
dira[22]~~
\sock.connect(myServerIP, myServerPort)
sock.resetBuffers
sock.waitConnectTimeout(2000)
if sock.isConnected
outA[20] := 1
delay_ms(500)
outA[20] := 0
else
outA[22] := 1
delay_ms(500)
outA[22] := 0
Server software
#!/usr/bin/env python
"""
A simple echo server
"""
import socket
import sqlite3
vt = sqlite3.connect("sicaklik.db")
im = vt.cursor()
#im.execute("CREATE TABLE lab1 (sicaklik)")
host = ''
port = 3422
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
while 1:
client, address = s.accept()
data = client.recv(size)
if data:
im.execute("INSERT INTO lab1 (sicaklik) VALUES (?) ", [data])
vt.commit()
client.send(data)
client.close()

Comments
This hardware uses Enc28j60 for the props enterhnet communications. The full system has 3 props, but the props treated individually, so the code might apply to your situation.
The site is in german, but google translate works pretty well. The guys are very nice and helpful.