Jump to content




LyqydNet Rednet API

api wireless networking

  • You cannot reply to this topic
104 replies to this topic

#81 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 March 2013 - 07:17 AM

Sorry, I've had quite a bit going on IRL recently. I haven't had a chance to sit down with the code and figure out what's going on just yet. I should have a chance to do so this weekend or the following week. Just to confirm, you are using the latest version of the master branch of LyqydNet from the github, correct? Knowing which version you are using will drastically speed things along when I do poke through it.

Also, if you could make sure that both computers are labelled, that would be great. And since the labels are used when attempting to connect to a computer by name, make sure that the label you are using matches the name of the computer that you're telling it to connect to. :)

#82 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 17 March 2013 - 04:57 PM

View Postshiry, on 08 March 2013 - 12:20 PM, said:

View PostLyqyd, on 07 March 2013 - 05:20 AM, said:

Is your server computer's label set to "testserver"? I will look into this and see if I can duplicate the bug.

Were you successful in duplicating the error?

Well, I was unsuccessful in duplicating the error. I ran your code exactly, on a correctly set up LyqydNet network, and it ran without issue. :)

If you're having trouble getting it to connect, make sure that all of the computers in the network are labelled. It may help to have a computer dedicated as a router. You've got the startup for each computer set up correctly as far as I can tell, so the labelling is the only issue I can think of. Let me know if you are still having issues and I can take a look at a world save if you're willing to upload one someplace. :)

#83 Timendainum

  • Members
  • 26 posts
  • LocationNether

Posted 23 November 2013 - 11:43 PM

I am using this API in conjunction with a slightly modified version of Lyqyd's filesserver to automate software updates on a computer network.

When I call sequential netfile.put() calls they fail, and it seems like I have to sleep() some to allow the next file to be sent.

Below is the function I am using. I think what may be happening is the last network transaction is not completed yet, therefore this one is failing, but I'm not sure. It is down in the net API where the it is failing at though.

local function pushUpdateToServer(serverLabel)
	--test for updating self
	if serverLabel == os.getComputerLabel() then
		print("Cannot push to self. Skipping " .. serverLabel .. ".")
		return
	end

	-- declarations
	local serverConnection = false
	local remoteDir = false
	--read files config
	local files = config.readConfig("/etc/files")
	
	--open server connection
	serverConnection, remoteDir = connection.open(serverLabel, port, timeout)
		if not serverConnection then
		print("Connection to " .. serverLabel .. " Failed!")
		return
	else
		print("Connected to ".. serverLabel .." Path: ".. remoteDir)
	end

	-- loop over files list and update files
	for k, v in pairs(files) do
		local path = shell.resolve(str.replace(v[1], fs.getName(v[1]), ""))
		local fullPath = shell.resolve(v[1])
		--try to create remote directory
		-- (this will happen a lot, may want to detect for it and create it conditionally)
		if path ~= "/" and path ~= "" then
			print("Sending mkdir " .. path)
			connection.send(serverConnection, "fileMakeDirectory", path)
						remoteDir = gatherResponse(serverConnection)
			print("Response: " .. remoteDir)
		end
		-- put the file
		write("Sending file: " .. fullPath .. " ")

		local success = false
		local retrys = 1
		while not success do
			write("..try" .. retrys)
			success = netfile.put(serverConnection, fullPath, fullPath, timeout)
			if retrys > 3 then
				break
			end
			
			if not success then
				retrys = retrys + 1
				sleep(1)
			end
		end
		if success then
			print("..success.")
		else
			write("..failed. <CR>")
			local junk = read()
			return
		end
	end

	--close server connection
	if connection.close(serverConnection) then
		serverConnection = false
		print("Connection Closed.")
	else
		print("Could not close connection!")
	end
end

You can see I've put in a retry system. It always seems to work on the second try.

Does anyone have any ideas on how I can improve this?

Edited by Timendainum, 23 November 2013 - 11:46 PM.


#84 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 November 2013 - 11:58 PM

Have you tried specifying a timeout value? Try a second or two to actually give the server a chance to respond.

#85 Timendainum

  • Members
  • 26 posts
  • LocationNether

Posted 24 November 2013 - 12:46 AM

View PostLyqyd, on 23 November 2013 - 11:58 PM, said:

Have you tried specifying a timeout value? Try a second or two to actually give the server a chance to respond.

Yeah, that was my first thought as well. I have tried setting the timeout to as high as 60. I have set the sleep time to as low as 0.01 and it works every time.

full script is here:
https://github.com/T...update/push.lua

Edited by Timendainum, 03 December 2013 - 05:02 PM.


#86 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 November 2013 - 03:38 AM

I've added an issue to the tracker on Github for LyqydNet for this problem. I'll work on this as time allows, hopefully I'll be able to take a whack at it soon.

#87 Timendainum

  • Members
  • 26 posts
  • LocationNether

Posted 24 November 2013 - 03:58 PM

Ah, okay. I totally expected it was something i was doing wrong.

I'm also working on a network peripheral Api and daemon. I may have some questions for you later this evening.

This Api is very cool. I've been having a lot of fun playing with it.

#88 Timendainum

  • Members
  • 26 posts
  • LocationNether

Posted 26 November 2013 - 06:28 PM

While writing my wireless peripheral API

API
http://pastebin.com/APNEz5BY

daemon
http://pastebin.com/XhaDnyZ8

I've noticed similar behavior with successive connections. I've had to put a sleep in before the connection to make sure successive connections will work.

#89 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 July 2014 - 04:32 AM

I've pushed my more recent progress on this from the development branch on the github repo over to the master branch. If anyone runs in to any issues with it, feel free to post them here or as issues on the github. Note that this is a rather big change, and scripts for previous versions of LyqydNet will be broken. This should be the last time I institute major breaking changes, as the overall API design is much better at this point. Most (if not all) functionality should still be there, and there are a couple things that work better than they previously did.

#90 Spartan_MiniMe

  • Members
  • 3 posts
  • LocationWashington DC, America

Posted 08 July 2014 - 01:04 AM

I am quite confused on how to install this. I have added all the api files to computercraft1.57.zip/assets/computercraft/lua/rom/apis and all the program files to computercraft1.57.zip/assets/computercraft/lua/rom/programs. However, when I attempt to run a computer as a router with
shell.run("lyqydnet")
shell.run("routed")
i get these outputs
File not found
File not found
File not found
File not found
File not found
SI
SI
I'm not sure if a installed it correctly... any help would be appreciated!

I put them in a code tag because i don't know how to put an image into the post.

#91 Spartan_MiniMe

  • Members
  • 3 posts
  • LocationWashington DC, America

Posted 08 July 2014 - 01:55 AM

Oh, never mind! I hadn't read the

Quote

No hard modification of the ROM files is necessary to run this.


#92 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 October 2014 - 04:12 AM

I've been spending a bit of time on this API this weekend, and I've pushed my work to the github repo. The majority of the work was resolving some longstanding issues of multiple packet processing passes, as well as updating to 1.6+ packet structures and concepts. I believe I've maintained backwards compatibility on the vanilla rednet side, so you should be able to use this with essentially all versions of ComputerCraft since tables were first allowed to be sent as rednet messages. The changes that made LyqydNet vastly better back in July did mean that versions that only allowed rednet to transmit strings would no longer be supported, and that has not changed. This version has been tested to work both with and without LyqydNet. I've been testing nsh and have successfully used it between two computers using LyqydNet as well as between a computer using LyqydNet and a computer not using LyqydNet. I believe I have the compatibility issues sorted out at this point.

#93 tec_SG

  • Members
  • 10 posts

Posted 03 November 2014 - 08:18 PM

Just one question, what way would be the best one to implement "turnOn()" for non-reachable routers/hosts (connected via LAN cables), so the network stack can try to send the data afterwards?

Afaik it will require pairing (multiple) Modem names with computer ID.

Edited by tec_SG, 03 November 2014 - 08:22 PM.


#94 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 03 November 2014 - 09:57 PM

When you say non reachable you mean ones where you have no idea what the name is?

local modem = peripheral.wrap("right")--#Assuming your modem is on the right.
local function turnOnEveryone()
  for _,i in pairs(modem.getNamesRemote()) do --#getNamesRemote grabs those peripheral names that you can't get, however through the wire.
	  if peripheral.getType(i) == "computer" then --#If the peripheral is a computer. This is in case you've got monitors and whatever connected
	    peripheral.call(i,"shutdown") --#Turn them off
	    sleep(0)
	    peripheral.call(i,"turnOn") --#Turn them on
	  end
    end
end


#95 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 November 2014 - 10:04 PM

That's an interesting question, actually. Within the context of LyqydNet, I think the easiest way to implement such a feature would be to force on packet receipt acknowledgement for all packets (which is a simple change, but would nearly double rednet traffic), then when a packet fails to be acknowledged, use existing host querying methods, but also iterate all available computer peripherals, checking the ID number against the ID the packet was intended for. If the correct computer is found, the turnOn() call would be made and the packet could be retried after a short sleep to allow it to initialize.

#96 tec_SG

  • Members
  • 10 posts

Posted 04 November 2014 - 08:24 AM

Or just pre-send turnOn() to the desired pc if it is on the network and then send the packet, afaik turnOn() does nothing if the pc is On. (startup doesn't trigger)

Still idk if there is a method to get names of the "modems" (like "computer_##" since they are not per PC) connected to a PC(locally) without the need of other PC and data transfer, or just inputting the ## numbers manually.

EDIT:
preferably it can be done easily with
computer.getID() call per every modem-PC in the network and then just send turnOn() to matching pair

EDIT:2
Is net.raw_send() used for both router-router and router-host communication.
Noticed only one hit for "transmit" so this is true

EDIT:3
So i did this: (from "net")
TurnOn_Packet=TurnOn_Packet or TurnOn_Broadcast or false
TurnOn_Broadcast=TurnOn_Broadcast or false

function raw_send (recipient, message, forceOn)
if forceOn or TurnOn_Packet then
  if recipent==65535 and (forceOn or TurnOn_Broadcast) then
   for _,v in ipairs(peripheral.getNames()) do--list peripherals
    if string.find(v,"computer_") then --if computer
	 pcall(peripheral.call,v,"turnOn")--turn on
	 --pcall in case something gets changed when iterating
	 sleep(0.1)
    end
   end
  else
   for _,v in ipairs(peripheral.getNames()) do--list peripherals
    if string.find(v,"computer_") then --if computer
	 t,PC=pcall(peripheral.call,v,"getID") --try to get ID
	 if t and PC==recipent then --if id OK
	  pcall(peripheral.call,v,"turnOn")--turn on
	  --pcall in case something gets changed when iterating
	  sleep(0.1)
	 end
    end
   end
   pcall(peripheral.call,"computer_"..recipent,"turnOn")
   sleep(0.1)
  end
end
peripheral.call(modemSide, "transmit", recipient, os.computerID(), message)
end

And if I'am right this should allow the packet to turn on the desired pc if the correct flag is on, but still my point is to add configs allowing to:

1: turn on routers that are needed to forward a packet
2: turn on host that is the recipent
so it would :
-not turn on computers not needed in the process
-not turn on computers just for network discovery (finding/checking routes)

and another flag to allow turnOn broadcasts (so i can send data to everywhere without turning the computers on manually)

So i ask for the features above to be implemented, since finding every send, and raw_send instance in this api without it deep knowledge and appending this configs by me would probably end with just making it "bORkeD"

Edited by tec_SG, 04 November 2014 - 08:14 PM.


#97 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 November 2014 - 05:28 AM

It's an interesting request. I have to ask, though. Why on earth are you expecting computers to be normally off? I've never encountered anyone else keeping their computers off all the time. Everybody I've talked to just leaves all of them on, or at least all of the infrastructure they've set up. I'm a little reluctant to add a feature that only one person (to my knowledge) would ever need. Maybe if you could further expound upon the reasons for keeping them turned off, I could better understand why you want it.

#98 tec_SG

  • Members
  • 10 posts

Posted 05 November 2014 - 06:11 AM

SMP reasons, chunk unload/server restart-> PCs are going off.

Edited by tec_SG, 05 November 2014 - 04:38 PM.


#99 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 November 2014 - 05:39 PM

Oh, that's actually a bug in the version of ComputerCraft you're using. The latest version doesn't have that bug.

I'll think about the feature request a bit more, though.

#100 tec_SG

  • Members
  • 10 posts

Posted 05 November 2014 - 07:31 PM

Tested it on CC 1.65 + Cauldron server, seems you are right sir. That should accelerate my programming sine the problem is solved at some point
.
But still it would be nice to have that functionality, for backwards compatibility, and for applications like redstone impulsator where you do not need the pc to be on all the time.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users