Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal


  • Content Count

  • Joined

  • Last visited

  • Days Won


Reputation Activity

  1. Like
    CptMercury reacted to MoonlightOwl in Stem - easy internet bridge   
    What is STEM?
    Did you ever want to have a linked card, but without this pair-to-pair limitations?
    Well, you have internet card. And that is already half of the solution. The other half is to use Stem.

    Stem is a message transmitter for your OpenComputers devices with internet cards.
    Using a small OpenOS library you can use Stem to send and receive messages. Unlike the standard `modem` component, Stem-messaging uses not addresses, but `channels`. You can send messages to any channels, and you can subscribe to any number of channels to listen for messages from them.
    The best way is to use HPM:
    hpm install stem If you do not have HPM, install it like this:
    pastebin run vf6upeAN If you do not want to use HPM repository, you can just use wget:
    wget https://gitlab.com/UnicornFreedom/stem/raw/master/stem.lua Example of a program using STEM
    local event = require('event') -- use STEM client library local stem = require('stem') -- open a connection to a STEM server -- the `stem.fomalhaut.me` is a default one local server = stem.connect('stem.fomalhaut.me') -- subscribe for messages from the channel with ID 'my-channel-id' server:subscribe('my-channel-id') -- then listen for events in a loop... while true do local name, channel_id, message = event.pull('stem_message') if name ~= nil then print(channel_id, message) end end -- ...or register an event listener event.listen('stem_message', function(_, _, channel_id, message) print(channel_id, message) end) -- you can also send message to the channel -- (you do not need to be subscribed to this channel, to send a message) server:send('my-channel-id', 'hello there') -- unsubscribe from channel server:unsubscribe('my-channel-id') -- completely close the connection to the STEM server server:disconnect()  
    That is all.
    But there is more.
    Web client
    If you open the link to Stem server in your browser: https://stem.fomalhaut.me/
    You will see some statistics and the web client. Enter your channel ID into the form, and you can send messages to your robot in real time, right from your phone, without even starting Minecraft.

    The web client is limited with UTF-8 encoding, though.
    (Using OpenOS you can send literally anything, as long as the message fits in 64kb of data.)
    Security Questions
    The channels by default do not have any special security measures applied. They do not have any authentication mechanisms, the do not have any encryption.
    Anyone who knows the ID of a channel can send a message to it and can listen for responses. But.
    The length of ID is 256 bytes. And that can be any bytes - from 0 to 255. That means, that you have 256^256 possible combinations for your ID. And that is a giant number. If you need to secure your channel - just use something long and incomprehensible as your ID.
    As an additional measure you can use end-to-end encryption, or anything else - this is up to you.
    Default STEM server uses HTTPS, and does not store any information - message in, message out.
    Self-hosted STEM solution
    For those of you who are strong in spirit and computer knowledge - there is a self-hosted option. You can build Stem server from sources and run it on your machine.
    This is also pretty easy. Additional instructions can be found on GitLab.
    Useful links
    GitLab repository: https://gitlab.com/UnicornFreedom/stem
    Protocol description: https://gitlab.com/UnicornFreedom/stem/wikis/protocol
    Default server: https://stem.fomalhaut.me/
    HPM package: https://hel.fomalhaut.me/#packages/stem
    If I forgot something - feel free to ask here, or in IRC (my nickname is Totoro there). Also the project contains at least one "Easter egg" feature, that can offer some interesting options if you know HTML/CSS/JS.
    The Stem protocol is open - you can modify it, you can create your own clients in any programming language, etc.
  2. Upvote
    CptMercury got a reaction from Molinko in How to write files from outside the directory?   
    Well, first of all, if you only need the message to contain one string, then you are better off by just sending the string as the message, so no need to make a table with that string, serialize the table transforming it into a string which is then send via the modem, once received, transformed back into a table which is then indexed to get the string you want to send...
    But anyways, I would assume the error with the serialization comes from trying to serialize a nil value. You're using a timeout with your event.pull, that means, event.pull returns nil if no modem_message was received within that 239 seconds. So either you simply remove the number specifying the timeout, or you add an if-statement checking whether you actually received a message and skip the serialization part when the message is nil.
    -- without the timeout, if this is possible, but it looks like you want your robot to execute some stuff every 239 seconds function loopWait() loopOff = false db.clear(1) me.store({name = "minecraft:record_wait"}, db.address, 1) selectEmpty() me.requestItems(db.address, 1, 1) ic.equip() robot.useUp() repeat _, _, _, _, _, serialized_message = event.pull("modem_message") received_table = require("serialization").unserialize(serialized_message) if recieved_table.loopSwitch == "off" then loopOff = true end robot.useUp() selectFull() ic.equip() robot.useUp() until loopOff == true robot.useUp() selectFull() me.sendItems() end -------------------------------- -- with an if statement verifying there actually was a message received function loopWait() loopOff = false db.clear(1) me.store({name = "minecraft:record_wait"}, db.address, 1) selectEmpty() me.requestItems(db.address, 1, 1) ic.equip() robot.useUp() repeat _, _, _, _, _, serialized_message = event.pull(239, "modem_message") if serialized_message then received_table = require("serialization").unserialize(serialized_message) if recieved_table.loopSwitch == "off" then loopOff = true end end robot.useUp() selectFull() ic.equip() robot.useUp() until loopOff == true robot.useUp() selectFull() me.sendItems() end But the easiest and best way would be to send your string directly as the message
    -- the computer sending the message modem.send(address, port, "off") -- receiving computer function loopWait() loopOff = false db.clear(1) me.store({name = "minecraft:record_wait"}, db.address, 1) selectEmpty() me.requestItems(db.address, 1, 1) ic.equip() robot.useUp() repeat _, _, _, _, _, message = event.pull(239, "modem_message") if message == "off" then loopOff = true end robot.useUp() selectFull() ic.equip() robot.useUp() until loopOff == true robot.useUp() selectFull() me.sendItems() end  
  3. Like
    CptMercury got a reaction from Hakz_Studios in I need help with my If-Then commands   
    in these if statements, you need to use relational operators. Since you want to see if you're variable is equal to a certain string, you need the '==' (two equal signs).
    So you're code would look like this
    -- local require commands start local component= require (“component”) local sides = require(“sides”) local rs = component.redstone local event = require(“event”) -- local os = require(“os”) remove this, the os lib does not need to be required, I think -- local require commands end -- Main function start local function main() local username, message = event.pull(“chat_message”) -- you head a period (.) between both variables -- problematic loop start if username == “Hakz_Studios” and message == “ Alice Refuel” then component.speech_box.say(“Refueling”) component.chat_box.say(“Refueling”) repeat local username,message = event.pull(“chat_message”) rs.setoutput(sides.bottom, 15) -- you need to give the redstone output a value, otherwise it wont turn on -- also, by putting it into a loop, the redstone output will be set a ton of times -- it helps putting the statement before the repeat until loop until username == “Hakz_Studios” and message == “Stop Refueling” -- restarting function function main() -- idk what is this line about, but i dont think it belongs here elseif username == “Hakz_Studios” and message == “Stop Refuel Systems” os.execute(“Shutdown”) -- it will look for a program called 'Shutdown' with a capital S else function main() -- also, dont know what you want to do here, do you want to start the function again (to have the code repeated endlessly) --problematic loop end end -- main function end end Some small info: you don't have to put brackets around your condition in the if-statements, you can, but it's not necessary.
    Also, here is a program that repeats the main loop over and over again, as I think that is what you want to do in your original code, if I'm wrong tho and misinterpreting you're code, just ignore my suggestion
    -- require libs local component = require("component") local rs = component.redstone local sides = require("sides") local event = require("event") -- main function local function main() local username, message = event.pull("chat_message") if username == "Hakz_Studios" and message == "Alice Refuel" then component.speech_box.say("Refueling") component.chat_box.say("Refueling") -- this time I set the redstone output once, and then wait for the message 'Stop refueling' then deactivate the redstoneoutput again rs.setOutput(sides.bottom, 15) repeat username, message = event.pull("chat_message") -- you dont have to use 'local' in front of username and message here, since you already created these variables at the top of the main function -- it will override these values but it actually doesnt matter since from this part you will skip to the end and these initial values for both variables -- wont be needed anymore until username == "Hakz_Studios" and message == "Stop Refueling" rs.setOutput(sides.bottom, 0) -- I assume you want to deactivate the redstone after you're done refueling elseif username == "Hakz_Studios" and message == "Stop Refuel System" then os.execute("Shutdown") -- again, this will start the program "Shutdown" with a capital "S" end -- as you can see, we skip the last else statement, as it will call the main function recursively, resulting in a overflow error pretty fast -- you could get away with returning a call to the main function, but this wouldnt be good practice eiter, I guess end -- we add a last while loop, which will repeat endlessly calling the main function while true do main() end I hope this helps.
    Also you did great for your first shot at programming!
  4. Upvote
    CptMercury reacted to payonel in High Precision computer.pull/event.pull   
    for a polite server load, we let the minecraft server runtime decide when to pick back up our threads, and thus we cannot give lower precision that we currently have.
  5. Upvote
    CptMercury got a reaction from floorwaxer2 in IC2 reactor control   
    Hey, here is a list of all methods for ic2 reactors.
    local component = require'component' local reactor = component.reactor reactor.getHeat() reactor.getMaxHeat() reactor.getReactorEUOutput() reactor.getReactorEnergyOutput() reactor.producesEnergy() You have to connect the reactor via an adapter.
  6. Like
    CptMercury reacted to Nexarius in Tank Display Program | now with energy and essentia too !   
    And just to push it over the top into the rediculous area I've doubled it again to 256! That should be enough for forever.
    (I even had a lot of trouble coming up with so many for testing)

  7. Upvote
    CptMercury got a reaction from augitesoul in systeminfo - well... showing system information...?   
    Looking good, neat program!
    Some advice for dealing with strings:
    If you want to print some text on your screen and insert some numbers/other variables/returns of functions etc. into that text, instead of writing one part of the text, writing the number, and write the second part of the text you can just concatenate(connect) the different strings and the numbers using the concat operator ..  (2 dots), then print it. In other words, combine all the different parts of the text first, and then write it to the screen. This will reduce the number of lines in your code and less screen operations are performed.
    io.write("string1") io.write("string2") -- # -> string1string2 -- # you get the same result with io.write("string1".."string2") -- # -> string1string2 -- # you can include numbers with io.write("string"..1.."string"..2) -- # -> string1string2 -- # you dont have to use the strings/numbers directly, variables containing strings and numbers work fine as well local s = "string" local num1 = 1 local num2 = 2 io.write(s..num1..s..num2) -- # -> string1string2 -- # one example of your code would be: line 55 - 59 term.write("Energy available/maximum: "..computer.energy().."/"..computer.maxEnergy().."\n") And one question: do you actually want the program to wait before printing a new set of information on the screen or do you just want to let your program yield in order to avoid "too long without yielding errors"?
  8. Upvote
    CptMercury got a reaction from augitesoul in Making the result of an HTTP request readable output   
    The main problem here is that "==" is used to compare two values and it returns true or false: 4 == 4 -> true; 4 == 5 -> false
    The other thing is that the response is not a string, but an iterator that will return the next line whenever you call it.
    local internet = require'internet' local url = '...' local response = interent.request(url) if response then for line in response do io.write(line.."\n") end end -- # response is an iterator, each time it's called it returns the next line/chunk, this is then stored in the var "line" -- # then you can use the var and print/write it, store it in a table etc  
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.