public async void PushProvision(ProvisionUpdate update) { var provisionData = new byte[33 + 64 + 65 + 2]; var offset = 0; Array.Copy(update.SSID, 0, provisionData, offset, update.SSID.Length); offset += 33; Array.Copy(update.Password, 0, provisionData, offset, update.Password.Length); offset += 64; var checkedId = CheckID(update.ID); Array.Copy(checkedId, 0, provisionData, offset, checkedId.Length); offset += 16; Array.Copy(update.Host, 0, provisionData, offset, update.Host.Length); offset += 16 + 1; // add 1 to account for structure padding? var byteArray = BitConverter.GetBytes(update.Port); Array.Copy(byteArray, 0, provisionData, offset, byteArray.Length); offset += byteArray.Length; provisionData[provisionData.Length - 2] = 0x0D; provisionData[provisionData.Length - 1] = 0x0A; await _serial.Write("provision" + char.MinValue+ "\r\n"); await _serial.Write(provisionData); await _serial.Write(TOKEN_DONE); }
public async void PushProvision(ProvisionUpdate update) { var provisionData = new byte[33 + 64 + 65 + 2]; Array.Copy(update.SSID, 0, provisionData, 0, update.SSID.Length); Array.Copy(update.Password, 0, provisionData, 33, update.Password.Length); var checkedId = CheckID(update.ID) + '\0'; Encoding.UTF8.GetBytes(checkedId, 0, checkedId.Length, provisionData, 33 + 64); provisionData[provisionData.Length - 2] = 0x0D; provisionData[provisionData.Length - 1] = 0x0A; await _serial.Write("provision" + char.MinValue+ "\r\n"); await _serial.Write(provisionData); await _serial.Write(TOKEN_DONE); }
private void button2_Click(object sender, EventArgs e) { if (_currentId == null) // Never connected to device return; // send provision var wifiItem = listBox1.SelectedItem as WifiAp; if (wifiItem == null) return; var provisionUpdate = new ProvisionUpdate { ID = _currentId, Password = Encoding.UTF8.GetBytes(textBox2.Text), SSID = wifiItem.SSID }; _provision.PushProvision(provisionUpdate); }