Hello everyone! I am having this weird issue with not being able to setup a network. Here is the error message:
Error: Failed to send network message, network 100002 does not exist in main.agc at line 80
and here is my code:
// Project: raspberry_piCOM
// Created: 2016-07-23
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "raspberry_piCOM" )
SetWindowSize( 1024, 768, 0 )
global net as integer
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
rem _type = 0 -> client, _type = 1 -> server
rem client -> on raspberry pi, server -> on computer
if getfileexists("raspberryPICOMconfig.txt") = 0
print("not found")
w = opentowrite("raspberryPICOMconfig.txt")
writestring(w,"1")
closefile(w)
sleep(100)
endif
w = opentoread("raspberryPICOMconfig.txt")
_types$ = readstring(w)
if _type = 1
net = HostNetwork("raspberryPI","host", 4100)
else
net = joinnetwork("raspberryPI","client")
endif
closefile(w)
global _type as integer
_type = val(_types$)
printc("program type: ")
if _type = 0 then print("Client")
if _type = 1 then print("Server")
do
mess$ = ""
if _type = 0
mess$ = checkMessages()
printc("message from network: ")
print(mess$)
else
mess$ = checkFileForUpdates()
printc("message from file: ")
print(mess$)
endif
if _type = 0
return$ = parseData(mess$)
printc("return data from parsing: ")
print(return$)
if return$ <> ""
sendMessageData(return$)
print("data sent")
endif
else
sendMessageData(mess$)
print("message sent")
endif
Sync()
loop
function checkMessages()
msg = GetNetworkMessage(net)
if msg <> -1
data$ = GetNetworkMessageString(msg)
DeleteNetworkMessage(msg)
endif
endfunction data$
function sendMessageData(data$)
msg = CreateNetworkMessage()
AddNetworkMessageString(msg, data$)
SendNetworkMessage(msg, 0, net)
DeleteNetworkMessage(msg)
endfunction
function parseData(data$)
rem format of data: |data:name,state|
return$ = ""
firstCount = CountStringTokens(data$, "|")
dim mainData$[10000]
for x=0 to firstCount
mainData$[x] = GetStringToken(data$, "|", x)
mainTitle$ = GetStringToken(mainData$[x], ":", 0)
if mainTitle$ = "pin"
subjectName$ = getstringtoken(mainData$[x], ",", 0)
stateData$ = GetStringToken(mainData$[x], ",", 1)
writeByte(val(subjectName$), val(stateData$))
endif
rem add more addresses
next
endfunction return$
function checkFileForUpdates()
if getFileExists("content.txt") = 1
r = opentoread("content.txt")
str$ = readstring(r)
closefile(r)
deletefile("content.txt")
endif
endfunction str$
I will say it is not the best code in the world, but I am building a basic communication app between my computer and raspberry pi, thank you for your help and suggestions!