MCPcopy Create free account
hub / github.com/SpacehuhnTech/espwebtool / clickConnect

Function clickConnect

src/App.js:48–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46
47 // Connect to ESP & init flasher stuff
48 const clickConnect = async () => {
49 if (espStub) {
50 await espStub.disconnect()
51 await espStub.port.close()
52 setEspStub(undefined)
53 return
54 }
55
56 const esploader = await connectESP({
57 log: (...args) => addOutput(`${args[0]}`),
58 debug: (...args) => console.debug(...args),
59 error: (...args) => console.error(...args),
60 baudRate: parseInt(settings.baudRate),
61 })
62
63 try {
64 toast.info('Connecting...', {
65 position: 'top-center',
66 autoClose: false,
67 toastId: 'connecting'
68 })
69 toast.update('connecting', {
70 render: 'Connecting...',
71 type: toast.TYPE.INFO,
72 autoClose: false
73 })
74
75 setConnecting(true)
76
77 await esploader.initialize()
78
79 addOutput(`Connected to ${esploader.chipName}`)
80 addOutput(`MAC Address: ${formatMacAddr(esploader.macAddr())}`)
81
82 const newEspStub = await esploader.runStub()
83
84 setConnected(true)
85 toast.update('connecting', {
86 render: 'Connected 🚀',
87 type: toast.TYPE.SUCCESS,
88 autoClose: 3000
89 })
90
91 //console.log(newEspStub)
92
93 newEspStub.port.addEventListener('disconnect', () => {
94 setConnected(false)
95 setEspStub(undefined)
96 toast.warning('Disconnected 💔', { position: 'top-center', autoClose: 3000, toastId: 'settings' })
97 addOutput(`------------------------------------------------------------`)
98 })
99
100 setEspStub(newEspStub)
101 setUploads(await loadFiles(esploader.chipName))
102 setChipName(esploader.chipName)
103 } catch (err) {
104 const shortErrMsg = `${err}`.replace('Error: ','')
105

Callers

nothing calls this directly

Calls 4

connectESPFunction · 0.90
formatMacAddrFunction · 0.90
loadFilesFunction · 0.90
addOutputFunction · 0.85

Tested by

no test coverage detected