PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → [WM17] Connexion réseau WIFI + IP statique
[WM17] Connexion réseau WIFI + IP statique
Débuté par Nicolas P., 12 sep. 2012 18:04 - 3 réponses
Posté le 12 septembre 2012 - 18:04
Bonjour,

Voila j'ai un bouton, lorsque je clique dessus, il recherche un réseau ayant comme SSID "gsMonSSID", et s'il le trouve, il se connecte à ce réseau sans fil avec le mot de passe "gsMonMDP".

Cela marche tes bien tant que le wifi est configuré en DHCP.

Mais comment rentrer une IP fixe + passerelle + DNS lorsque le reseau n'est pas en DHCP ?

Ci-dessous le code de mon bouton.

Merci d'avance !





ListePoint est une chaîne
sID est une chaîne
sSSID est une chaîne
sBSSID est une chaîne
sSecu est une chaîne
sPuiss est une chaîne
wifitrouve est un booléen = Faux

LIB1 = ""

ListePoint = WiFiDétectePointAccès()
POUR TOUTE CHAÎNE PointAcces DE ListePoint SEPAREE PAR RC

SI ExtraitChaîne(PointAcces,2, TAB) = gsMonSSid ALORS
wifitrouve = Vrai

sID = ExtraitChaîne(PointAcces,1, TAB)
sSSID = ExtraitChaîne(PointAcces,2, TAB)
sBSSID = ExtraitChaîne(PointAcces,3, TAB)
sSecu = ExtraitChaîne(PointAcces,4, TAB)
sPuiss = ExtraitChaîne(PointAcces,5, TAB)

LIB1 = "Reseau wifi "+gsMonSSid+" trouvé !"+ RC + RC + "ID : "+ sID + RC + "SSID : " + sSSID + RC + "BSSID : " + sBSSID + RC + "Securite : " + sSecu + RC + "Puissance signal : " + sPuiss +RC+RC+RC+RC
FIN

FIN

SI wifitrouve ALORS
LIB1 += "Tentative de connexion au réseau " + sSSID + "..."+RC+RC

Identifiant est une chaîne
Identifiant = WiFiAjouteRéseau(sSSID, sBSSID, sSecu, gsMonMDP, Vrai)

SI Identifiant <> " " ALORS

SI WiFiConnecte(Identifiant)=Vrai ALORS
LIB1 += "CONNEXION ETABLIE !"
SINON
LIB1 += "CONNEXION IMPOSSIBLE :(" + RC + ErreurInfo()
FIN

FIN
FIN
Posté le 12 septembre 2012 - 18:53
J'ai oublié de préciser, c'est une appli ANDROID ;)
Posté le 17 septembre 2012 - 12:47
j'ai "un peu" avancé dans mon problème. En faisant quelques recherche, apparemment il est possible de le faire en passant par du code java.

J'ai donc créé une fonction globale JAVA :





public static void appel_java()
{

android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_USE_STATIC_IP, "0");
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS1, "8.8.8.8");
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS2, "8.8.4.4");
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_GATEWAY, "192.168.0.77");
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0");
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_IP, "192.168.0.155");

}





Apparemment il faut modifier les droits lors de la compilation, j'ai donc activer la permission "WRITE_SETTINGS".
Mais à la compilation, j'ai des erreurs :





Echec de la création de l'application Android <C:\Mes Projets Mobile\lanceur_tablet\Exe\lanceur_tablet.apk>.

Ligne de commande : "C:\Program Files\Java\jdk1.7.0_04\bin\javac.exe" -encoding UTF-16LE -nowarn -source 1.5 -target 1.5 -d bin\classes -bootclasspath "C:\Program Files (x86)\Android\android-sdk\platforms\android-15\android.jar" gen\com\masociete\lanceur_tablet\*.java src\com\masociete\lanceur_tablet\wdgen\*.java -classpath "libs"


Erreur retournée :
src\com\masociete\lanceur_tablet\wdgen\GWDCPProceduresGlobales.java:29: error: cannot find symbol
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_USE_STATIC_IP, "0");
^
symbol: method getContentResolver()
location: class GWDCPProceduresGlobales
src\com\masociete\lanceur_tablet\wdgen\GWDCPProceduresGlobales.java:30: error: cannot find symbol
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS1, "8.8.8.8");
^
symbol: method getContentResolver()
location: class GWDCPProceduresGlobales
src\com\masociete\lanceur_tablet\wdgen\GWDCPProceduresGlobales.java:31: error: cannot find symbol
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS2, "8.8.4.4");
^
symbol: method getContentResolver()
location: class GWDCPProceduresGlobales
src\com\masociete\lanceur_tablet\wdgen\GWDCPProceduresGlobales.java:32: error: cannot find symbol
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_GATEWAY, "192.168.0.77");
^
symbol: method getContentResolver()
location: class GWDCPProceduresGlobales
src\com\masociete\lanceur_tablet\wdgen\GWDCPProceduresGlobales.java:33: error: cannot find symbol
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0");
^
symbol: method getContentResolver()
location: class GWDCPProceduresGlobales
src\com\masociete\lanceur_tablet\wdgen\GWDCPProceduresGlobales.java:34: error: cannot find symbol
android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_IP, "192.168.0.155");
^
symbol: method getContentResolver()
location: class GWDCPProceduresGlobales
6 errors





apparemment le soucis viens de getContentResolver()...
Je ne suis vraiment pas un spécialiste du java, si quelqu'un a une idée pour résoudre mon problème...

Merci d'avance.
Posté le 17 septembre 2012 - 13:41
Je me reponds a moi-meme :
j'avais oublié le getContexteApplication()

Par contre quand je lace l'appli sur la tablette Android, ca ne semble pas fonctionner...

Je ne trouve pas pourquoi...


import android.content.*;
import android.provider.Settings.Secure;

public static void appel_java()
{

android.provider.Settings.System.putString(getContexteApplication().getContentResolver(), android.provider.Settings.System.WIFI_USE_STATIC_IP, "1");
android.provider.Settings.System.putString(getContexteApplication().getContentResolver(), android.provider.Settings.System.WIFI_STATIC_IP, "192.168.0.155");
android.provider.Settings.System.putString(getContexteApplication().getContentResolver(), android.provider.Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0");
android.provider.Settings.System.putString(getContexteApplication().getContentResolver(), android.provider.Settings.System.WIFI_STATIC_GATEWAY, "192.168.0.77");
android.provider.Settings.System.putString(getContexteApplication().getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS1, "8.8.8.8");
android.provider.Settings.System.putString(getContexteApplication().getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS2, "8.8.4.4");

}