Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use wido to realize networking in adrduino

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to use wido to achieve networking in adrduino, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

# include

# include

# include

# include

# include "utility/debug.h"

# define WiDo_IRQ 7

# define WiDo_VBAT 5

# define WiDo_CS 10

Adafruit_CC3000 WiDo = Adafruit_CC3000 (WiDo_CS, WiDo_IRQ, WiDo_VBAT

SPI_CLOCK_DIVIDER) / / you can change this clock speed

# define WLAN_SSID "Tenda_XXXXX" / / cannot be longer than 32 characters!

# define WLAN_PASS "12345678"

/ / Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2

# define WLAN_SECURITY WLAN_SEC_WPA2

# define TIMEOUT_MS 2000

Void setup () {

Serial.begin (115200)

/ * Initialise the module * /

Serial.println (F ("\ nInitialising the CC3000..."))

If (! WiDo.begin ()

{

Serial.println (F ("Unable to initialise the CC3000! Check your wiring?"))

While (1)

}

/ * NOTE: Secure connections are not available in 'Tiny' mode!

By default connectToAP will retry indefinitely, however you can pass an

Optional maximum number of retries (greater than zero) as the fourth parameter.

, /

Serial.println (F ("Connecting Router/AP"))

If (! WiDo.connectToAP (WLAN_SSID, WLAN_PASS, WLAN_SECURITY) {

Serial.println (F ("Failed!"))

While (1)

}

Serial.println (F ("Router/AP Connected!"))

/ * Wait for DHCP to complete * /

Serial.println (F ("Request DHCP"))

While (! WiDo.checkDHCP ()

{

Delay; / / ToDo: Insert a DHCP timeout!

}

}

Void loop () {

Static Adafruit_CC3000_Client tcpClient

Static unsigned long heartRate = millis ()

If (! tcpClient.connected ()) {

Serial.println ("Try to connect the Local Server")

TcpClient.close ()

/ * Set the target ip address and connection port * /

Uint32_t ip = WiDo.IP2U32 (192, 168, 0, 12)

TcpClient = WiDo.connectTCP (ip, 8080)

If (! tcpClient.connected ()) {

Serial.println (F ("Couldn't connect to server! Make sure TCP Test Tool is running on the server."))

While (1)

}

}

Else if (millis ()-heartRate > 1000) {

HeartRate = millis (); / / Update time stamp of the microcontroller system

Char clientString [30]

Sprintf (clientString, "% s%d%s", "Wido heartRate:", heartRate/1000, "s\ r\ n")

Serial.println (clientString)

TcpClient.fastrprintln (clientString)

}

/ * Read data until either the connection is closed, or the timeout is reached. , /

Unsigned long lastRead = millis ()

While (tcpClient.connected () & & (millis ()-lastRead < TIMEOUT_MS)) {

While (tcpClient.available ()) {

Char c = tcpClient.read ()

Serial.print (c)

LastRead = millis ()

/ / Disable sending message for a moment

HeartRate = millis ()

}

}

}

The above content is how to use wido to achieve networking in adrduino. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report