public bool CycleWifi() { string localIP = WifiLocal.Localhost.ToString(); try { // Close all WifiBasic connections WifiLocal.CloseAll(true); //WifiLocal.Close(cai); Wait(4000); // Get new cert to restart WifiBasic connections CertManager.CertificateManager certMgr = new CertManager.CertificateManager(); // Restart Wifi Connection if (certMgr.IsLocalValid) { WifiLocal.SetWifi(System.Net.IPAddress.Parse(localIP), certMgr.GetCertificate(CertManager.CertificateManager.CertificateTypes.Symantec20172020)); Wait(7000); WifiLocal.ScanConnectedAppliances(false, null); return(true); } } catch { return(false); } return(false); }
//If the product responds to a ping, set the ping data and also check its MQTT connection from the Trace. Also re-enable the Trace if it has been lost due to disconnection/reboot/power loss void p_PingCompleted(object sender, PingCompletedEventArgs e) { string ip = (string)e.UserState; if (e.Reply != null) { lock (lockObj) { //gets the list of appliances from WifiBasic System.Collections.ObjectModel.ReadOnlyCollection <ConnectedApplianceInfo> cio = WifiLocal.ConnectedAppliances; //Selects the appliance based on IP address ConnectedApplianceInfo cai = cio.FirstOrDefault(x => x.IPAddress == ip); //If an appliance with the specified IP address is found in the list... if (cai != null) { mqttresp = cai.IsTraceOn; //check if Trace is currently enabled if (!cai.IsTraceOn) { //if it's not and Revelation is also not enabled, enable Revelation if (!cai.IsRevelationConnected) { WifiLocal.ConnectTo(cai); } else { //If Revelation is enabled, enable Trace WifiLocal.EnableTrace(cai, true); } mqttresp = false; } else { //If the Trace is enabled and Revelation is also connected, close the Revelation connection if (cai.IsRevelationConnected) { WifiLocal.CloseRevelation(System.Net.IPAddress.Parse(cai.IPAddress)); } mqttresp = true; } } // Else if the IP address is not found in the WifiBasic list, connection has been lost else { mqttresp = false; } if (e.Reply.Status == IPStatus.Success) { pingresp = ip + "\t" + e.Reply.RoundtripTime + "ms" + "\t" + mqttresp.ToString(); } else { pingresp = ip + "\t" + e.Reply.Status.ToString() + "\t" + mqttresp.ToString(); } responses.Add(pingresp); } } }
bool RevelationConnect(ConnectedApplianceInfo cai) { int revatt = 0; while (revatt < ATTEMPTMAX) { try { if (cancel_request) { return(false); } revatt++; if (cai != null) { //if it's not and Revelation is also not enabled, enable Revelation if (!cai.IsRevelationConnected) { WifiLocal.ConnectTo(cai); Wait(2000); } if (!cai.IsRevelationConnected) { //If Revelation is enabled, enable Trace continue; } //If the Trace is enabled and Revelation is also connected return if (cai.IsRevelationConnected) { return(true); } } else { MessageBox.Show("Revelation was not able to be connected due to error in WifiBasic." + "If persists, you may need to close Widebox and try again.", "Error: Unable to start", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } catch { MessageBox.Show("Revelation was not able to be connected due to error in WifiBasic." + "If persists, you may need to close Widebox and try again.", "Error: Unable to start", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } return(true); }
public bool SendRevelation(ConnectedApplianceInfo cai) { bool revconnect = false; try { if (cai != null && !cai.IsRevelationConnected) { // Connect revelation WifiLocal.ConnectTo(cai); Wait(2000); } // Send Revelation message if (cai != null && cai.IsRevelationConnected) { WifiLocal.SendRevelationMessage(cai, new RevelationPacket() { API = 0xF1, Opcode = 00, Payload = paybytes, }); Wait(2000); revconnect = true; } // Close revelation if (revconnect) { WifiLocal.CloseRevelation(System.Net.IPAddress.Parse(cai.IPAddress)); //WifiLocal.Close(cai); Wait(2000); return(true); } else { return(false); } } catch { MessageBox.Show("Catastrophic SendRevelation error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
public void Scan() { if (cancel_request) { return; } string localIP = WifiLocal.Localhost.ToString(); try { WifiLocal.ScanConnectedAppliances(true, localIP); Wait(2000); } catch { MessageBox.Show("Catastrophic Scan error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
/// <summary> /// Send a Reveal Message over the Mqtt connection. /// Use WifiLocal.ConnectedAppliances to get the list of current scanned and/or connected appliances. /// </summary> /// <param name="connectedAppliance">The connected Applicance</param> /// <param name="destination">Address to send the message</param> /// <param name="api">Reveal Api</param> /// <param name="opcode">Reveal Opcode</param> /// <param name="isFeedback">Set true if the message is a feedback</param> /// <param name="payload">payload bytes</param> public void SendRevealMessageOverMQTT(ConnectedApplianceInfo connectedAppliance, byte destination, byte api, byte opcode, bool isFeedback, byte[] payload) { RevealPacket pkt = new RevealPacket(api, opcode, 0, destination, isFeedback, payload); WifiLocal.SendMqttMessage(connectedAppliance, pkt.ToMqtt()); }
/// <summary> /// Send a Reveal Message over the Mqtt connection. /// Use WifiLocal.ConnectedAppliances to get the list of current scanned and/or connected appliances. /// </summary> /// <param name="connectedAppliance">The connected Applicance</param> /// <param name="pkt">Reveal packet containing the command or feedback to be sent</param> public void SendRevealMessageOverMQTT(ConnectedApplianceInfo connectedAppliance, RevealPacket pkt) { WifiLocal.SendMqttMessage(connectedAppliance, pkt.ToMqtt()); }
/// <summary> /// Send a Reveal Message List over the Revelation connection. /// Use WifiLocal.ConnectedAppliances to get the list of current scanned and/or connected appliances. /// </summary> /// <param name="connectedAppliance">The connected Applicance</param> /// <param name="pktList">Reveal packet list containing the commands and/or feedbacks to be sent</param> public void SendRevealMessageOverRevelation(ConnectedApplianceInfo connectedAppliance, List <RevealPacket> pktList) { WifiLocal.SendRevelationMessage(connectedAppliance, pktList.ToRevelation()); }
private void BTN_GET_Click(object sender, EventArgs e) { if (BTN_GET.Text == "Get") { try { DialogResult dialogurl; if (!CB_Suppress.Checked) { if (MessageBox.Show("Before continuing, please verify that IP Address of " + TB_IP.Text + " is currently" + " listed within WifiBasic and UITracer is NOT running. If not, press 'No' on this window and open WifiBasic then press 'Data Start'" + " and finally, press 'Scan Appliances' to populate the list in WifiBasic.", "Verify IP Address is Listed", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { return; } } string get = "get"; BTN_GET.Text = "Running"; BTN_GET.Enabled = false; CB_EMEAP.Enabled = false; CB_NARS.Enabled = false; CB_NARP.Enabled = false; CB_Custom.Enabled = false; CB_Org.Enabled = false; CB_Org.Checked = false; CB_MQTT.Enabled = false; CB_MQTT.Checked = false; BTN_Reset.Enabled = false; TB_IP.Enabled = false; BTN_Payload.Enabled = false; CB_Legacy.Enabled = false; //CycleWifi(); //Wait(2000); System.Collections.ObjectModel.ReadOnlyCollection <ConnectedApplianceInfo> cio = WifiLocal.ConnectedAppliances; ConnectedApplianceInfo cai = cio.FirstOrDefault(x => x.IPAddress == TB_IP.Text); byte[] orgbytes = Encoding.ASCII.GetBytes(OrgSelection()); byte[] paybytes = Encoding.ASCII.GetBytes(PaySelection()); if (cai != null) { if (RevelationConnect(get, cai)) { if (SendRevelation(TB_IP.Text, paybytes, orgbytes)) { for (int i = 0; i < ATTEMPTMAX; i++) { if (mqtt_url.Contains(".")) { break; } else { Wait(1000); } } } } if (mqtt_url != "") { if (mqtt_url == "0") { mqtt_url = "DEFAULT"; } if (org_id == "0") { org_id = "DEFAULT"; } dialogurl = MessageBox.Show("The MQTT URL for " + TB_IP.Text + " is currently " + mqtt_url + "." + " The ORG ID for " + TB_IP.Text + " is currently " + org_id + "." + " Request completed. Closing all open connections.", "Get MQTT URL and ORG ID", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dialogurl = MessageBox.Show("The MQTT URl/Org ID for " + TB_IP.Text + " was NOT returned successfuly." + " Request completed. Closing all open connections.", "Get MQTT URL and ORG ID", MessageBoxButtons.OK, MessageBoxIcon.Information); } Reset(false); mqtt_url = ""; TB_IP.Enabled = true; BTN_Reset.Enabled = true; BTN_Payload.Enabled = true; WifiLocal.CloseAll(true); return; } else { MessageBox.Show("Connection failed. Verify IP Address of " + TB_IP.Text + " has been correctly typed" + " and that the IP Address is listed within WifiBasic.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Reset(false); return; } } catch { Reset(false); mqtt_url = ""; TB_IP.Enabled = true; BTN_Reset.Enabled = true; BTN_Payload.Enabled = true; return; } } else { try { Reset(false); TB_IP.Enabled = true; BTN_Reset.Enabled = true; return; } catch { Reset(false); return; } } }
bool RevelationConnect(string sent, ConnectedApplianceInfo cai) { int revattempt = 0; while (revattempt < ATTEMPTMAX) { revattempt++; try { if (cai != null) { if (sent == "set") { if (!cai.IsRevelationConnected) { WifiLocal.ConnectTo(cai); Wait(2000); } if (!cai.IsRevelationConnected) { continue; } if (cai.IsRevelationConnected) { return(true); } } if (sent == "get") { if (!cai.IsTraceOn) { //if it's not and Revelation is also not enabled, enable Revelation if (!cai.IsRevelationConnected) { WifiLocal.ConnectTo(cai); Wait(2000); } if (cai.IsRevelationConnected) { //If Revelation is enabled, enable Trace WifiLocal.EnableTrace(cai, true); Wait(2000); } } if (cai.IsTraceOn) { return(true); } } } else { MessageBox.Show("Revelation connection failed. Verify IP Address of " + TB_IP.Text + " has been correctly typed" + " and that the IP Address is listed within WifiBasic.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } catch { if (sent == "get") { MessageBox.Show("Connection failed. Verify that UITracer is NOT RUNNING and is Closed. You may need to close" + "Widebox and try again.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Revelation connection failed. Verify IP Address of " + TB_IP.Text + " has been correctly typed" + " and that the IP Address is listed within WifiBasic.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(false); } } /*if (CycleWifi()) * { * try * { * if (!cai.IsRevelationConnected) * { * WifiLocal.ConnectTo(cai); * Wait(2000); * } * * if (cai.IsRevelationConnected) * return true; * * else * { * MessageBox.Show("Revelation connection failed. You may need to close" + * " Widebox and/or power cycle the product and try again.", "Error: Unable to connect.", * MessageBoxButtons.OK, MessageBoxIcon.Exclamation); * return false; * } * * * } * catch { return false; } * }*/ MessageBox.Show("Revelation connection failed. You may need to close" + " Widebox and/or power cycle the product and try again.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); }
public bool SendRevelation(string ips, byte[] paybytes, byte[] orgbytes)//, ConnectedApplianceInfo cai) { int revattempt = 0; bool revconnect = false; // Check CAI and set IP address System.Collections.ObjectModel.ReadOnlyCollection <ConnectedApplianceInfo> cio = WifiLocal.ConnectedAppliances; ConnectedApplianceInfo cai = cio.FirstOrDefault(x => x.IPAddress == ips); var myDestination = WifiLocal.ConnectedAppliances.FirstOrDefault(i => i.IPAddress.Equals(ips)); // See if Revelation is Connected and attempt to connect until it is while (!revconnect && (revattempt < ATTEMPTMAX)) { try { revattempt++; // Send Revelation message(s) if (myDestination != null && cai.IsRevelationConnected) { if (CB_MQTT.Checked || BTN_GET.Text == "Running") { WifiLocal.SendRevelationMessage(myDestination, new RevelationPacket() { API = 0xF0, Opcode = 00, Payload = paybytes, }); Wait(2000); } if (CB_Org.Checked || BTN_GET.Text == "Running") { WifiLocal.SendRevelationMessage(myDestination, new RevelationPacket() { API = 0xF0, Opcode = 00, Payload = orgbytes, }); Wait(2000); } revconnect = true; } // Close revelation if (revconnect) { WifiLocal.CloseRevelation(System.Net.IPAddress.Parse(cai.IPAddress)); Wait(2000); return(true); } } catch { MessageBox.Show("Revelation connection failed. Verify IP Address of " + TB_IP.Text + " has been correctly typed" + " and that the IP Address is listed within WifiBasic.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } MessageBox.Show("Revelation connection failed. Verify IP Address of " + TB_IP.Text + " has been correctly typed" + " and that the IP Address is listed within WifiBasic.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); }
private void BTN_Payload_Click(object sender, EventArgs e) { if (BTN_Payload.Text == "Set") { try { DialogResult dialogurl; if (!Valid()) { DialogResult dialogResult = MessageBox.Show("No selection made. Please choose a selection from the check boxes.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!CB_Suppress.Checked) { if (MessageBox.Show("Before continuing, please verify that IP Address of " + TB_IP.Text + " is currently" + " listed within WifiBasic. If not, press 'No' on this window and open WifiBasic then press 'Data Start'" + " and finally, press 'Scan Appliances' to populate the list in WifiBasic.", "Verify IP Address is Listed", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { return; } } string set = "set"; bool result = false; BTN_Payload.Text = "Running"; BTN_Payload.Enabled = false; CB_EMEAP.Enabled = false; CB_NARS.Enabled = false; CB_NARP.Enabled = false; CB_Custom.Enabled = false; CB_MQTT.Enabled = false; CB_Org.Enabled = false; BTN_Reset.Enabled = false; TB_IP.Enabled = false; BTN_GET.Enabled = false; CB_Legacy.Enabled = false; //CycleWifi(); //Wait(2000); System.Collections.ObjectModel.ReadOnlyCollection <ConnectedApplianceInfo> cio = WifiLocal.ConnectedAppliances; ConnectedApplianceInfo cai = cio.FirstOrDefault(x => x.IPAddress == TB_IP.Text); byte[] paybytes = Encoding.ASCII.GetBytes(PaySelection()); byte[] orgbytes = Encoding.ASCII.GetBytes(OrgSelection()); if (cai != null) { if (RevelationConnect(set, cai)) { result = SendRevelation(TB_IP.Text, paybytes, orgbytes);//, cai); Wait(2000); } if (result) { dialogurl = MessageBox.Show("The MQTT URl for " + TB_IP.Text + " WAS CHANGED successfuly." + " Request completed. Closing all open connections.", "Set MQTT URL", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dialogurl = MessageBox.Show("The MQTT URl for " + TB_IP.Text + " was NOT CHANGED successfuly." + " Request completed. Closing all open connections.", "Set MQTT URL", MessageBoxButtons.OK, MessageBoxIcon.Information); } Reset(false); BTN_Payload.Enabled = true; TB_IP.Enabled = true; BTN_Reset.Enabled = true; BTN_GET.Enabled = true; WifiLocal.CloseAll(true); return; } else { MessageBox.Show("Unable to connect. Verify IP Address of " + TB_IP.Text + " has been correctly typed" + " and that the IP Address is listed within WifiBasic.", "Error: Unable to connect.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Reset(false); return; } } catch { Reset(false); return; } } else { try { Reset(false); TB_IP.Enabled = true; BTN_Reset.Enabled = true; return; } catch { Reset(false); return; } } }