You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I used this library and was excited because it solved my problem to connect an esp8266 to the WiFi without ap mode.
I am testing v1 and it works fine, but v2 does not transmit the keys (SSID and PASSWORD) or my esp8266 does not receive the transmission.
this is my code:
// Within a fragment
package com.example.kiinbalam.ui.slideshow
import android.content.Context
import android.content.Context.WIFI_SERVICE
import android.net.wifi.WifiManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.example.esp_touch.*
import com.example.kiinbalam.EspTouchApp
import com.example.kiinbalam.R
import java.util.*
import kotlin.collections.ArrayList
class SlideshowFragment : Fragment() {
private lateinit var slideshowViewModel: SlideshowViewModel
private val TAG: String = SlideshowFragment::class.java.simpleName
val KEY_PROVISION = "provision"
val KEY_PROVISION_REQUEST = "provision_request"
private val mStations: List<EspProvisioningResult>? = ArrayList()
private lateinit var mProvisioner: EspProvisioner
private lateinit var mWifiManager: WifiManager
private lateinit var mBroadcastObserver: Observer<String>
private var mWifiFailed = false
private var mTime: Long = 0
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val request = EspProvisioningRequest.Builder(requireContext())
.setSSID("INFINITUM559F_2.4".toByteArray())
.setBSSID(TouchNetUtil.convertBssid2Bytes("44:a1:91:c3:e1:6c"))
.setPassword("hsadkfljasdñlkfjsdfklas".toByteArray())
.build()
mProvisioner = EspProvisioner(requireContext())
mWifiManager = context?.getSystemService(WIFI_SERVICE) as WifiManager
mBroadcastObserver = Observer {
val connected = TouchNetUtil.isWifiConnected(mWifiManager)
if(!connected && mProvisioner.isProvisioning()) {
mWifiFailed = true
mProvisioner.stopProvisioning()
}
}
EspTouchApp().getInstance()?.observeBroadcastForever(mBroadcastObserver)
mTime = System.currentTimeMillis()
// mProvisioner.startSync(mListener)
slideshowViewModel = ViewModelProvider(this).get(SlideshowViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_slideshow, container, false)
val textView: TextView = root.findViewById(R.id.text_slideshow)
val btnScan = root.findViewById<Button>(R.id.btn_scan_devices)
btnScan.setOnClickListener {
mProvisioner.startProvisioning(request, ProvisionListener())
val result = mWifiManager.scanResults
result.forEach {
println(it.SSID)
println(it.BSSID)
println("...........................")
}
}
slideshowViewModel.text.observe(viewLifecycleOwner, Observer {
textView.text = it
})
return root
}
inner class ProvisionListener : EspProvisioningListener {
override fun onStart() {
Log.d(TAG, "ProvisionListener onStart: ")
}
override fun onResponse(result: EspProvisioningResult) {
val mac = result.bssid
val host = result.address!!.hostAddress
Log.d(TAG, "ProvisionListener onResponse: $mac $host")
/*runOnUiThread(Runnable {
mStations.add(result)
mStationAdapter.notifyItemInserted(mStations!!.size - 1)
})*/
}
override fun onStop() {
Log.d(TAG, "ProvisionListener onStop: ")
/*runOnUiThread(Runnable {
if (!mWifiFailed && mStations!!.isEmpty()) {
mBinding.messageView.setText(R.string.esptouch2_provisioning_result_none)
}
mBinding.stopBtn.setEnabled(false)
mBinding.progressView.setVisibility(View.GONE)
})*/
mTime = System.currentTimeMillis() - mTime
Log.e(TAG, "Provisioning task cost $mTime")
}
override fun onError(e: Exception) {
Log.w(TAG, "ProvisionListener onError: ", e)
mProvisioner.stopProvisioning()
/*activity?.runOnUiThread(Runnable {
val message = getString(
R.string.esptouch2_provisioning_result_exception,
e.localizedMessage
)
mBinding.messageView.setText(message)
})*/
}
}
}
I would like to know what is i´m doing wrong, thanks in advance
The text was updated successfully, but these errors were encountered:
Hi, I used this library and was excited because it solved my problem to connect an esp8266 to the WiFi without ap mode.
I am testing v1 and it works fine, but v2 does not transmit the keys (SSID and PASSWORD) or my esp8266 does not receive the transmission.
this is my code:
I would like to know what is i´m doing wrong, thanks in advance
The text was updated successfully, but these errors were encountered: