I'm pretty new to TCP connections and very new to Autoit.
I'm trying to connect to a game server that I admin in order to receive server data (online players, chat logs, etc) and to send TelNet commands to the server if needed (Ban player, kick player, etc)
Looking at the TCP functions for Autoit, I only see a place for IP and Port information, but the server has an admin password, and I have no idea how to incorporate the password into the mix.
I would appreciate any insight into how I would go about connecting to the server and receiving data.
Use IP:Port to connect and then you do the communication with the server
This is an old script I wrote to connect thru telnet to my router in order to change the IP.
TCPStartup()
TrayTip("Changing IP adress!", "...connecting...", 10)
$router_IP = "192.168.1.1"
$port = "23" ; standard telnet port
$username = "admin"
$pass = "****"
Dim $ConnectedSocket = -1
$ConnectedSocket = TCPConnect($router_IP, $port)
If $ConnectedSocket = -1 Then
TrayTip("Changing IP adress!", "Error! Cant connect!", 10)
Sleep(3000)
Exit
EndIf
TrayTip("Changing IP adress!", "Connected.", 10)
$old = ""
$ret = TCPSend($ConnectedSocket, $username & #LF)
Sleep(2000)
$ret = TCPSend($ConnectedSocket, $username & #LF)
Sleep(2000)
$ret = TCPSend($ConnectedSocket, $username & #LF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP address!", $old, 10)
Sleep(2000)
$ret = TCPSend($ConnectedSocket, $pass & #CRLF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP adress!", $old, 10)
Sleep(2000)
$ret = TCPSend($ConnectedSocket, "sh" & #CRLF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP adress!", $old, 10)
Sleep(3000)
$ret = TCPSend($ConnectedSocket, "ifconfig nas_8_35 down" & #CRLF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP adress!", $old, 10)
Sleep(10000)
$ret = TCPSend($ConnectedSocket, "ifconfig nas_8_35 up" & #CRLF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP adress!", $old, 10)
Sleep(2000)
$ret = TCPSend($ConnectedSocket, "exit" & #CRLF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP adress!", $old, 10)
Sleep(2000)
$ret = TCPSend($ConnectedSocket, "exit" & #CRLF)
$old &= TCPRecv($ConnectedSocket, 2048)
TrayTip("Changing IP adress!", $old, 10)
Sleep(5000)
Can't remember why I send the username 3 times thou...
Also, since you are new, these are the places to start:
Autoit for absolute beginners
Autoit 1-2-3
Autoit Tcp examples and scripts
TELNET
Good luck!
Related
I am writing a code in AutoIt, but need help with a kill switch to stop any processes that I accidently started.
Below is the example of the code that I started that I need a kill switch added to it.
HotKeySet('{PGDN}', 'Intro')
HotKeySet('{F3}', 'ENTgac')
HotKeySet('{F4}', 'LockedENT')
HotKeySet('{F5}', 'VDI')
HotKeySet('{F6}', 'SecurityHold')
HotKeySet('{F7}', 'Printer')
HotKeySet('{F9}', 'AllThingsZ')
HotKeySet('{F10}', 'Bitlocker')
HotKeySet('{F11}', 'Chrome')
While 1
Sleep(50)
WEnd
Func Intro ()
Send('Username: ' & #CRLF)
Send('Computer name: ' & #CRLF)
Send('R' & #CRLF)
Send('Callback number: ' & #CRLF)
Send('Teleworking: ')
EndFunc
Func ENTgac ()
Send("User unable to login and receiving error: 'Must Use Windows Hello error'" & #CRLF)
Send('Had user moved into Pending OU for No Valid Card' & #CRLF)
Send('Had allownongac pushed to INSERT CPU NAME' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func LockedENT ()
Send('Confirmed account lock through cmd > Account Active: Locked' & #CRLF)
Send('Unlocked in NIQ, advised user to login' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func AllThingsZ ()
Send('In Zscaler Updated Policy, Updated App, Clear Logs, Repair App, Restart Service' & #CRLF)
EndFunc
Func Bitlocker ()
Send('User was prompted for Bitlocker Recovery Key' & #CRLF)
Send('Verified user' & #CRLF)
Send('Recited Bitlocker Recovery Key to user' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func VDI ()
Send('Guided user through obtaining an secureauth otp code: otp.gsa.gov' & #CRLF)
Send('Guided user through logging into vdi.anywhere.gsa.gov and selecting Light Version for web access' & #CRLF)
Send('User was successfully able to open Standard Desktop')
EndFunc
Func Chrome ()
Send('Made sure Google Chrome was up to date' & #CRLF)
Send('Cleared cookies/cache/history (Settings > Privacy and Security > Clear Browsing Data > Time Range (All Time) > Clear Data)')
EndFunc
Func SecurityHold ()
Send('Provided user with RISSO group email address to contact for approval: risso#gsa.gov' & #CRLF)
Send('User was put in a Security Hold due to failure to complete ROB' & #CRLF)
Send('Submitted Re-Enable request for the user: Enter RITM' & #CRLF)
Send('Submitted Security Compliance Training on users behalf: Enter RITM')
EndFunc
Func Printer ()
Send('Remoted in COMPUTER NAME via BigFix' & #CRLF)
Send('Pressed the “Windows” and “R” keys at the same time' & #CRLF)
Send('Ran printer server by location listed in KB0026350' & #CRLF)
Send('Connected to printer' & #CRLF)
Send('Confirmed test page printed successfully')
EndFunc
Thank you again for any assistance provided. I will provide any information that is needed as quickly as I can.
I have attempted to add like a "Terminate" like below:
Func Terminate()
Exit
;EndSwitch
EndFunc ;==>Terminate
But when I attempt to run it, it does not work
I can't figure out how to use the check_http module of Icinga to use a http proxy.
I tried to achieve this using the following entry in hosts.conf.
object Host "host.local.ch" {
import "generic-host"
address = "192.168.200.20"
vars.http_vhosts["http"] = {
http_uri = "/"
http_proxy = "127.0.0.1"
http_proxy_port = 5016
}
}
I found a script, edited it and create files for the example usage with Icinga, find it here:
https://github.com/ozzi-/icinga-check-http-proxy
Save the following script (/etc/icinga2/scripts/check_http_proxy.sh):
#!/bin/bash
# Author: ozzi- , forked from scott.liao (https://github.com/shazi7804/icinga-check-http-proxy)
# Description: ICINGA2 http check with proxy support
# startup checks
if [ -z "$BASH" ]; then
echo "Please use BASH."
exit 3
fi
if [ ! -e "/usr/bin/which" ]; then
echo "/usr/bin/which is missing."
exit 3
fi
wget=$(which wget)
if [ $? -ne 0 ]; then
echo "Please install wget."
exit 3
fi
# Default Values
ssl=""
useragent=""
host=""
port=""
proxy=""
url="/"
times=1
timeout=5
warning=700
critical=2000
certificate=""
bindaddress=""
#set system proxy from environment
getProxy() {
if [ -z "$1" ]; then
echo $http_proxy | awk -F'http://' '{print $2}'
else
echo $https_proxy | awk -F'http://' '{print $2}'
fi
}
# Usage Info
usage() {
echo '''Usage: check_http_proxy [OPTIONS]
[OPTIONS]:
-p PORT Port to connect to (default: 80)
-u URL URL path (default: /)
-H HOSTNAME Destination Hostname
-a USERAGENT Sends a useragent and mimics other request headers of a browser
-s Use HTTPS proxy (default connecting to proxy via http)
-P PROXY Sets the proxy ip:port (i.e. 127.0.0.1:8840)
-w WARNING warning threshold in milliseconds (default: 700)
-c CRITICAL Critical threshold in milliseconds (default: 2000)
-n TRIES Number of connection attempts (default: 1)
-t TIMEOUT Seconds to wait for connection (timeout) (default: 5)
-C CERTIFICATE Path to a client certificate (PEM and DER file types supported)
-b IP Bind address for wget (default: IP of primary networking interface)'''
}
# Check which threshold was reached
checkTime() {
if [ $1 -gt $critical ]; then
echo -n "CRITICAL"
elif [ $1 -gt $warning ]; then
echo -n "WARNING"
else
echo -n "OK"
fi
}
# Return code value
getStatus() {
if [ $1 -gt $critical ]; then
return 2
elif [ $1 -gt $warning ]; then
return 1
else
return 0
fi
}
#main
#get options
while getopts "c:p:s:a:w:u:P:H:n:t:C:b:" opt; do
case $opt in
c)
critical=$OPTARG
;;
p)
port=$OPTARG
;;
s)
ssl=1
;;
a)
useragent=$OPTARG
;;
w)
warning=$OPTARG
;;
u)
url=$OPTARG
;;
P)
proxy=$OPTARG
;;
H)
hostname=$OPTARG
;;
n)
times=$OPTARG
;;
t)
timeout=$OPTARG
;;
C)
client_certificate=$OPTARG
;;
b)
bindaddress=$OPTARG
;;
*)
usage
exit 3
;;
esac
done
#define host with last parameter
host=$hostname
#hostname is required
if [ -z "$host" ] || [ $# -eq 0 ]; then
echo "Error: host is required"
usage
exit 3
fi
#set proxy from environment if available and no proxy option is given
if [ -z "$proxy" ]; then
proxy="$(getProxy ssl)"
fi
#use ssl or not
if [ -z "$ssl" ]; then
header="HTTP"
proxy_cmd="http_proxy=$proxy"
url_prefix="http://"
else
header="HTTPS"
proxy_cmd="https_proxy=$proxy"
url_prefix="https://"
fi
#different port
if [ -z "$port" ]; then
url="${url_prefix}${host}${url}"
else
url="${url_prefix}${host}:${port}${url}"
fi
start=$(echo $(($(date +%s%N)/1000000)))
if [ -z "$useragent" ]; then
if [ -z "$client_certificate" ]; then
#execute and capture execution time and return status of wget
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} $url
status=$?
elif [ -n "$client_certificate" ]; then
#execute and capture execution time and return status of wget with client certificate
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} --certificate=$client_certificate $url
status=$?
fi
else
if [ -n "$client_certificate" ]; then
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} --certificate=$client_certificate $url \
--header="User-Agent: $useragent" \
--header="Accept: image/png,image/*;q=0.8,*/*;q=0.5" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
status=$?
else
#execute with fake user agent and capture execution time and return status of wget
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} $url \
--header="User-Agent: $useragent" \
--header="Accept: image/png,image/*;q=0.8,*/*;q=0.5" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
status=$?
fi
fi
end=$(echo $(($(date +%s%N)/1000000)))
#decide output by return code
if [ $status -eq 0 ] ; then
echo "${header} $(checkTime $((end - start))): $((end - start))ms - ${url}|time=$((end - start))ms;${warning};${critical};0;"
getStatus $((end - start))
exit $?
else
case $status in
1)
echo "${header} CRITICAL: Generic error code ($status) - ${url}"
;;
2)
echo "${header} CRITICAL: Parse error ($status) - ${url}"
;;
3)
echo "${header} CRITICAL: File I/O error ($status) - ${url}"
;;
4)
echo "${header} CRITICAL: Network failure ($status) - ${url}"
;;
5)
echo "${header} CRITICAL: SSL verification failure ($status) - ${url}"
;;
6)
echo "${header} CRITICAL: Authentication failure ($status) - ${url}"
;;
7)
echo "${header} CRITICAL: Protocol errors ($status) - ${url}"
;;
8)
echo "${header} CRITICAL: Server issued an error response ($status) - ${url}"
;;
*)
echo "${header} UNKNOWN: $status - ${url}"
exit 3
;;
esac
exit 2
fi
Icinga command definition (/etc/icinga2/conf.d/commands.conf):
object CheckCommand "check-http-proxy" {
command = [ ConfigDir + "/scripts/check_http_proxy.sh" ]
arguments += {
"-p" = {
value = "$chp_port$"
description = "Port to connect to (default: 80)"
}
"-u" = {
value = "$chp_url$"
description = "URL path (default: /)"
}
"-H" = {
required = true
value = "$chp_hostname$"
description = "Destination Hostname"
}
"-s" = {
value = "$chp_ssl$"
description = "Use HTTPS proxy (default: http proxy)"
}
"-P" = {
required = true
value = "$chvp_proxy$"
description = "Sets the proxy ip:port (i.e. 127.0.0.1:8840)"
}
"-a" = {
value = "$chp_useragent$"
description = "Sends a useragent and mimics other request headers of a browser"
}
"-w" = {
value = "$chp_warning_timeout$"
description = "Warning threshold in milliseconds (default: 700)"
}
"-c" = {
value = "$chp_critical_timeout$"
description = "Critical threshold in milliseconds (default: 2000)"
}
"-b" = {
value = "$chp_bind_adr$"
description = "Bind address for wget (default: IP of primary networking interface)"
}
"-n" = {
value = "$chp_tries$"
description = "Number of connection attempts (default: 1)"
}
"-t" = {
value = "$chp_timeout$"
description = "Seconds to wait for connection (timeout) (default: 5)"
}
"-C" = {
value = "$chp_certificate$"
description = "Path to a client certificate (PEM and DER file types supported)"
}
}
}
Usage in /etc/icinga2/conf.d/hosts.conf
object Host "sub.domain.ch" {
check_command = "check-http-proxy"
vars.chp_hostname = "sub.domain.ch"
vars.chp_proxy = "127.0.0.1:5016"
}
I have opened an RDP session using AutoIt. Here is the code:
$host = "" ; <---- IP
$hGUI = GUICreate("Terminal Serveur", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2")
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$oRDP.DesktopWidth = 800
$oRDP.DesktopHeight = 600
$oRDP.Fullscreen = False
$oRDP.ColorDepth = 16
$oRDP.AdvancedSettings3.SmartSizing = True
$oRDP.Server = $host
$oRDP.UserName = "" ; <--- Username
$oRDP.Domain = ""
$oRDP.AdvancedSettings2.ClearTextPassword = "" ; <--- Password
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()
$oShel = ObjCreate("shell.application")
$oShel_Ctrl = GUICtrlCreateObj($oShel, 64, 44, 800, 600)
GUICtrlSetStyle($oShel_Ctrl , $WS_VISIBLE)
GUISetState(#SW_SHOW, $hGUI)
Send ("#r") ; !!
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
$oRDP.Disconnect()
Exit
EndSwitch
WEnd
Now, I want to launch an application in the RDP session. I tried " Send(#r) " in order to send the path with a function like SendKeys but this command is execute on my computer and not on the remote computer.
How can I do please?
Send alt + home. This open the windows search in the rdp session, which you can then send it text e.g. send("notepad")
send({enter})
Update:
A much simpler alternative:
Change the Remote Desktop Connection Settings (not in the control
code, but in the usual windows shorcut. But it seems that could be done in the AutoIt code with the keyboardhook setting keyboardhook setting ) .
Look for the Options button, in the window when launching remote desktop.
On the Local Resources Tab select Windows key combinations are applied in full-screen mode only.
Change this line in your code:
$oRDP.Fullscreen = True
Include a pause to ensure the control has been loaded
Sleep(5000)
Send ("#r")
Previous answer:
Let my suggest a workaround not very 'elegant' but should work (tested ok):
In the remote desktop make a shorcut to the Windows Virtual Keyword (On-Screen Keyboard or OSK)
Find the position of the shorcut icon
In your code send a double click at this position to start the on-screen keyboard
Then send clicks to the positions of the desired keys
Something like this:
Sleep(5000)
MouseClick("left",512,191,2) ;start virtual keyword
Sleep(1000)
MouseClick("left",553,807,1) ;click
Sleep(100)
MouseClick("left",633,740,1)
Sleep(1000)
Send("notepad")
Sleep(1000)
Send("{ENTER}")
(Aside note: For any executable with a shortcut on the remote desktop simply send double click, without the need of the virtual keyboard)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am creating a basic installer in autoit. After compiling the script, I got the error Unable to open the script file when trying to run it.
The Script:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Resources\unnamed.ico
#AutoIt3Wrapper_Outfile=..\..\..\Desktop\Minecraft Server Launcher Installer.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe, rt_rcdata, Launcher
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt, rt_rcdata, Licence
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <resources.au3>
$msgbox1 = MsgBox(36, "Minecraft Server Launcher Installer", "Do you want to install the Launcher?")
If $msgbox1 = 6 Then
GUICreate("Minecraft Server Launcher Installer", 373, 325)
GUICtrlCreateLabel("Read the following agreement. Scroll down to view the rest of the agreement.", 10, 10)
GUICtrlCreateEdit(_ResourceGetAsString("Licence"), 10, 51, 350, 191, $WS_VSCROLL + $ES_READONLY + $ES_MULTILINE)
GUICtrlCreateLabel("Do you accept all the terms of the license agreement? Selecting No" & #CRLF & "cancels the installation. You must accept the agreement to install.", 10, 250)
$YES = GUICtrlCreateButton("Yes", 204, 296, 75, 23)
$NO = GUICtrlCreateButton("No", 290, 296, 75, 23)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $YES
Choose_Loc()
Case $NO
Exit
EndSwitch
WEnd
EndIf
Func Choose_Loc()
GUIDelete()
GUICreate("Minecraft Server Launcher Installer", 363, 108)
GUICtrlCreateLabel("Choose Install Location", 10, 5)
$INPUT = GUICtrlCreateInput("C:\Program Files (x86)\KnarCraft\Minecraft Server Launcher", 10, 40, 255, 22)
$BROWSE = GUICtrlCreateButton("Browse...", 275, 40, 80, 23)
$CANCEL = GUICtrlCreateButton("Cancel", 275, 75, 80, 23)
$OK = GUICtrlCreateButton("OK", 185, 75, 80, 23)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $CANCEL
Exit
Case $OK
Install($INPUT)
Case $BROWSE
$FOLDER = FileSelectFolder("Choose Install Location...", "", 7)
If Not $FOLDER = "" Then GUICtrlSetData($INPUT, $FOLDER)
EndSwitch
WEnd
EndFunc ;==>Choose_Loc
Func Install($INPUT)
_ResourceSaveToFile(GUICtrlRead($INPUT) & "\Bungee Minecraft Server Launcher.exe", "Launcher", $RT_RCDATA, 0, 1)
FileCreateShortcut(GUICtrlRead($INPUT) & "\Bungee Minecraft Server Launcher.exe", #DesktopDir & "\Bungee Minecraft Server Launcher.ink")
GUIDelete()
If Not #error Then
MsgBox(36, "Finished", "Installation completed with no errors. Please enjoy your new software.")
Else
MsgBox(16, "Finished", "The installation was interrupted by an error and the software may not work.")
EndIf
Exit
EndFunc ;==>Install
I know that it's this line that creates the error:
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt, rt_rcdata, Licence
But I don't know why or how to fix it. I had the same problem with:
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe, rt_rcdata, Launcher
I know that it's the Res_Add line because if I remove that line, the error will disappear.
I stopped using the res file stuff, and switched to FileInstall() :
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe",#TEMPDIR & "\Bungee Minecraft Server Launcher.exe")
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt",#TEMPDIR & "\Licence.txt")
Then you just use the file. Also, your paths are different:
Autoit\{BUNGEE MINECRAFT SERVER LAUNCHER.EXE}
Autoit\Bungee Server Launcher\{LICENCE.TXT}
Open up a command prompt and check the full path :
cd C:\Users\Kristian\SkyDrive\Autoit & dir licence.txt /b /s
Another solution would be to make the text file a variable. Open the file in SciTE, replace the regular expression ^(.*)$ by "$1" & #CRLF &_, then copy and paste it into the script.
Here is the code with FileInstall() and a couple fixes. I tested with different paths, and it worked. Functions should be self-contained, so I made them mostly internal. Ideally, you'd have them do a Return SetError() and put the MsgBox() outside the function call.
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Resources\unnamed.ico
#AutoIt3Wrapper_Outfile=..\..\..\Desktop\Minecraft Server Launcher Installer.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
; Target path of temp files - you should add code to delete these when done
$LAUNCHPATH = #TempDir & "\BMSLauncher.exe"
$LICENCEPATH = #TempDir & "\BMSLicence.txt"
; Check if the install files exist, and if not, output to console
$EXIST1 = FileExists("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe")
$EXIST2 = FileExists("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt")
If Not $EXIST1 Or Not $EXIST2 Then
ConsoleWrite("ERROR! FILE(S) NOT FOUND!" & #CRLF)
If Not $EXIST1 Then ConsoleWrite("LAUNCHER FILE NOT FOUND!" & #CRLF)
If Not $EXIST2 Then ConsoleWrite("LICENCE FILE NOT FOUND!" & #CRLF)
EndIf
; Copy files to destination
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe", $LAUNCHPATH, 1)
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt", $LICENCEPATH, 1)
; Read licence file to variable
$LICENCE = FileRead($LICENCEPATH)
$msgbox1 = MsgBox(36, "Minecraft Server Launcher Installer", "Do you want to install the Launcher?")
If $msgbox1 = 6 Then
$EULAGUI = GUICreate("Minecraft Server Launcher Installer", 373, 325)
GUICtrlCreateLabel("Read the following agreement. Scroll down to view the rest of the agreement.", 10, 10)
GUICtrlCreateEdit($LICENCE, 10, 51, 350, 191, $WS_VSCROLL + $ES_READONLY + $ES_MULTILINE)
GUICtrlCreateLabel("Do you accept all the terms of the license agreement? Selecting No" & #CRLF & "cancels the installation. You must accept the agreement to install.", 10, 250)
$YES = GUICtrlCreateButton("Yes", 204, 296, 75, 23)
$NO = GUICtrlCreateButton("No", 290, 296, 75, 23)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $NO
Exit
Case $YES
GUIDelete($EULAGUI)
Choose_Loc()
EndSwitch
WEnd
EndIf
Func Choose_Loc()
Local $LOCGUI = GUICreate("Minecraft Server Launcher Installer", 363, 108)
GUICtrlCreateLabel("Choose Install Location", 10, 5)
$INPUT = GUICtrlCreateInput("C:\Program Files (x86)\KnarCraft\Minecraft Server Launcher", 10, 40, 255, 22)
$BROWSE = GUICtrlCreateButton("Browse...", 275, 40, 80, 23)
$CANCEL = GUICtrlCreateButton("Cancel", 275, 75, 80, 23)
$OK = GUICtrlCreateButton("OK", 185, 75, 80, 23)
GUISetState(#SW_SHOW)
While 1
; you could make the switch guigetmsg() without $msg, idk what's best practice here
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $CANCEL
Exit
Case $OK
Local $INSTALLPATH = GUICtrlRead($INPUT)
If FileExists($INSTALLPATH) Then
GUIDelete($LOCGUI)
Install($LAUNCHPATH, $INSTALLPATH)
EndIf
Case $BROWSE
$FOLDER = FileSelectFolder("Choose Install Location...", "", 7)
If Not $FOLDER = "" Then GUICtrlSetData($INPUT, $FOLDER)
EndSwitch
WEnd
EndFunc ;==>Choose_Loc
Func Install($FPATH, $IPATH)
Local $ERROR
; you should check for a trailing slash on the $IPATH input
$IPATH &= "\Bungee Minecraft Server Launcher.exe"
FileCopy($FPATH, $IPATH)
$ERROR = #error
FileCreateShortcut($IPATH, #DesktopDir & "\Bungee Minecraft Server Launcher.ink")
If Not #error And Not $ERROR Then
MsgBox(64, "Finished", "Installation completed with no errors. Please enjoy your new software.")
Else
MsgBox(16, "Finished", "The installation was interrupted by an error and the software may not work.")
EndIf
Exit
EndFunc ;==>Install
Make sure the file is in the same dir as the script and Try:
#AutoIt3Wrapper_Res_File_Add=Licence.txt, rt_rcdata, Licence
If you still have problems, try to turn off UPX.
I am having a problem in sending Arduino data into my database. I am currently using WAMPSERVER. I have an arduino mini w/ ATMEGA 328 and I am using ENC28J60. The problem is I have tried different libraries and examples to send data into the server but I failed. I just notice that some libraries are not compatible with my enc28J60. I have tried UIPEthernet.h, Ethernet.h, etherShield.h and EtherCard.h. The etherShield.h and EtherCard.h seemed to work just fine. But I prefer to use EtherCard.h because I heard etherShield is the older lib. I know a little php.
I think the things that might guide me is to see a working example of using the EtherCard.h library demonstrating the sending of sensor data from arduino into my database. The network setup I am currently working on is that, the ENC28J60 is connected in my home network with an ip address of 192.168.10.10. The server to which I placed the database is my laptop with an IP address of 192.168.10.2. I am placing the php files in this directory C:\wamp\www. I hope I have explained it well. I'm sorry for my English.
I am currently working of a port of my homewatch server from Arduino Uno w Ethernet lib to AVR-NETIO with Ethercard lib (or UIPEthernet).
On the server side there is a Apache/PHP/MySQL server.
To update data on a webserver connected database, you can use POST or GET requests to a php web page. These data can then be added easily to a database and the same or another web page can also display the data of the database.
<?php
require 'dbhelp.php';
//header('Content-type: text/plain');
echo "<html>";
echo "<head>";
echo "<meta name='viewport' content='width=device-width, user-scalable=false, initial-scale=1;'>";
echo "</head>";
echo "<body>" . "<h2>Temperatur und Luftfeuchte</h2>";
// GET requests are sent as a query string on the URL:
// GET index.html?name1=value&name2=value HTTP/1.1
// Host: about.com
// http://192.168.0.40/homewatch/index.php?channel=1&temp=165&humidity=80&datetime=010120131234
if($DEBUG){
print("<pre>");
print_r($_GET);
print("</pre>");
}
openDB();
if( isset($_GET['channel']) && isset($_GET['temp']) && isset($_GET['humidity']) )
{
if($DEBUG)
echo "<p>addData()";
$c=$_GET['channel'];
$t=$_GET['temp'];
$h=$_GET['humidity'];
addData($c, $t, $h);
if($DEBUG)
echo "<p>all done";
//listData();
echo "<p>OK updated data for channel:" . $c . "</p>";
}
else
{
if($DEBUG)
echo "listData()";
//listData();
//echo "<p>missing arg";
}
echo "<p><a href='linechart_hour.php'>Stunden-Übersicht</a></p>";
echo "<p><a href='barchart_days.php'>Tages-Übersicht</a></p>";
echo "<p><a href='http://www.unwetterzentrale.de/uwz/getwarning_de.php?plz=41363&uwz=UWZ-DE&lang=de'>Unwetterwarnungen Jüchen</a></p>";
echo showAllCharts();
//#################################################################################
// see http://code.google.com/p/googlechartphplib/wiki/GettingStarted
//#################################################################################
// don't forget to update the path here
require './lib/GoogleChart.php';
$chart = new GoogleChart('lc', 500, 200);
// manually forcing the scale to [0,100]
$chart->setScale(0,100);
// add one line
$data = new GoogleChartData(array(49,74,78,71,40,39,35,20,50,61,45));
$chart->addData($data);
// customize y axis
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawTickMarks(false)->setLabels(array(0,50,100));
$chart->addAxis($y_axis);
// customize x axis
$x_axis = new GoogleChartAxis('x');
$x_axis->setTickMarks(5);
$chart->addAxis($x_axis);
echo $chart->toHtml();
//#################################################################################
// END
//#################################################################################
echo "<p>v0.9" . "</body>" . "</html>";
?>
the dbhelp.php file creates the DB automatically if not already exists:
<?php
//global dbhelp.php file
$server="localhost";
$user="root";
$passwd="password";
$names=array(
1 => "Aussen",
2 => "Schlaf",
3 => "Andreas");
$DEBUG=false;
function openDB(){
global $DEBUG;
global $user;
global $passwd;
$link = mysql_connect("localhost", $user, $passwd);
if(!$link){
echo "SqlConnect failed";
echo mysql_error();
}
else
if($DEBUG)
echo "SqlConnect OK";
$query="CREATE database IF NOT EXISTS avrdb;";
$result = mysql_query($query, $link);
if(!$result){
echo "CreateDB failed";
echo mysql_error();
}
else
if($DEBUG)
echo "CreateDB OK";
$result = mysql_select_db("avrdb", $link);
if(!$result){
echo "SelectDB failed";
echo mysql_error();
}
else
if($DEBUG)
echo "SelectDB OK";
$query="CREATE TABLE IF NOT EXISTS `avrtemp` (" .
"`id` int(11) NOT NULL AUTO_INCREMENT, " .
"`channel` int(11), " .
"`temp` int(11), " .
"`humidity` int(11), " .
"`date_time` TIMESTAMP, " .
"PRIMARY KEY (`id`) );";
$result = mysql_query($query, $link);
if(!$result){
echo "CreateTable failed";
echo mysql_error();
}
else
if($DEBUG)
echo "CreateTable OK";
return true;
}
...
function addData($c,$t,$h){
global $DEBUG;
$lastStoredDateTime=getLastStoredDateTime();
if($DEBUG){
echo "<p>" . $c . "</p>\n";
echo "<p>LastDateTime=".$lastStoredDateTime."</p>\n";
}
// add data but do not save seconds (use 00)
$query="INSERT INTO avrtemp (`channel`,`temp`,`humidity`,`date_time`)".
" VALUES ( $c,$t,$h,".
// " DATE_FORMAT(NOW()),".
" DATE_FORMAT('".$lastStoredDateTime."', ".
" '%Y-%c-%d %H:%i') )";
if($DEBUG)
echo "<p>" . $query;
$result = mysql_query($query);
if(!$result){
echo "addData failed";
echo mysql_error();
}
else
if($DEBUG)
echo "addData OK";
}
The Arduino posts (using GET) updated data every 5 minutes. The data arrives at the Arduino via 433MHz wireless sensors every minute or so.
Using the Ethernet Lib the data update is done via
char cBuf[maxBuf+1];
const char getHttpString[] =
"GET /homewatch/index.php?channel=%i&temp=%i&humidity=%i&time=%i\0";
...
// and send data: /index.php?channel=1&temp=165&humidity=80&datetime=010120131234
if (client.connect(server, 80)) {
Serial.println("connected. Send GET...");
snprintf(cBuf, maxBuf,
getHttpString,
sensorData[idxChannel].channel,
sensorData[idxChannel].temp,
sensorData[idxChannel].humidity,
sensorData[idxChannel].time_long
);
Serial.println(F("####"));
Serial.println(cBuf);
Serial.println(F("####"));
client.println(cBuf);
...
https://github.com/hjgode/homewatch/blob/master/arduino/SketchBook/WebClientTemperature/WebClientTemperature.ino:
The string "GET /homewatch/index.php?channel=%i&temp=%i&humidity=%i&time=%i\0" is simply filled with actual sensor data and the server saves that to its database.
The Ethercard lib comes with similar examples: see the examples noipClient, pachube and webclient. Unfortunately I was not yet able to adopt these for my AVR-NETIO.
The code to post (GET) some data to the server I am currently working is
void sendData(int idxChannel){
Serial.print(F("in sendData for idx=")); Serial.println(idxChannel);
byte sd;
int channel=sensorData[idxChannel].channel;
int temp=sensorData[idxChannel].temp;
int humidity=sensorData[idxChannel].humidity;
char* stime="201301011122";
stime=printDateTime((char*)&stime, 13, sensorData[idxChannel].time_long);
if(sensorData[idxChannel].bUpdated==0){
//nothing new
if (MYDEBUG==0){
Serial.println(F("leaving for not updated channel data"));
goto exit_sendData;
}
else
{
sensorData[idxChannel].channel=idxChannel;
sensorData[idxChannel].temp=222;
sensorData[idxChannel].humidity=55;
sensorData[idxChannel].time_long=now();
}
}
// generate two fake values as payload - by using a separate stash,
// we can determine the size of the generated message ahead of time
sd = stash.create();
stash.print("0,");
stash.println((word) millis() / 123);
stash.print("1,");
stash.println((word) micros() / 456);
stash.save();
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("GET http://$F/homewatch/index.php?channel=$D&temp=$D&humidity=$D&time=$S" "\r\n"
"Host: $F" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website,
channel,
temp,
humidity,
stime,
website, stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
exit_sendData:
lastConnectionTime = now();//millis();
Serial.println(F("...end of sendData()"));
}
As you see, there is a formatted string
PSTR("GET http://$F/homewatch/index.php?channel=$D&temp=$D&humidity=$D&time=$S"
which is filled with variables. $F fills from Flash Memory, $D a number var, $S from a RAM memory string. Using this without my SensorCode (which uses Interrupts) is working.