Arduino+GSM A6程序主机链接错误:串口报CME ERROR:58
Hey there! Let’s dig into that CME ERROR:58 you’re facing. First, a quick note: this error usually points to invalid parameters in your AT command sequence, but since your code worked locally with Apache, the issue is almost certainly related to how 000webhost handles incoming requests vs. your local server. Here’s what to fix:
1. 000webhost Enforces HTTPS (Your Big Culprit)
Most free 000webhost accounts now force HTTPS connections—but you’re trying to connect over plain HTTP (port 80). This mismatch triggers the error because the server rejects your unencrypted request, and the GSM module interprets that as invalid parameters.
To fix this:
- Enable SSL on your GSM A6 before initiating the TCP connection
- Switch to port 443 (HTTPS)
- Update your POST request to use the
https://URL
2. Fix HTTP Request Formatting
Your Content-Length line has an extra \r\n that might be throwing off the request structure. Serial3.println() automatically adds a \r\n to the end of each line, so adding another one creates an unintended extra blank line.
3. Replace Fixed Delays with Response Waiting
Fixed delay() calls work for local testing, but 000webhost’s network might have higher latency. Waiting for the module’s "CONNECT OK" response ensures you only send data once the connection is fully established.
Modified Working Code
Here’s your updated send() function with all fixes applied:
// Helper function to wait for a specific response from GSM module bool waitForResponse(String target, unsigned long timeout) { unsigned long startTime = millis(); while (millis() - startTime < timeout) { if (Serial3.available()) { String line = Serial3.readStringUntil('\n'); Serial.println(line); // Echo to monitor for debugging if (line.indexOf(target) != -1) { return true; } } } return false; } void send() { delay(500); Serial3.println("AT+CIPSHUT\r"); waitForResponse("SHUT OK", 2000); Serial3.println("AT+CIPMUX=0\r"); waitForResponse("OK", 1000); Serial3.println("AT+CGATT=1\r"); waitForResponse("OK", 1000); Serial3.println("AT+CSTT=\"internet\",\"\",\"\"\r"); waitForResponse("OK", 1000); Serial3.println("AT+CIICR\r"); waitForResponse("OK", 2000); Serial3.println("AT+CIFSR\r"); waitForResponse(".", 2000); // Wait for IP address (contains dots) // Enable SSL for HTTPS connection Serial3.println("AT+CIPSSL=1\r"); waitForResponse("OK", 1000); // Connect to 000webhost over HTTPS (port 443) Serial3.println("AT+CIPSTART=\"TCP\",\"test.000webhostapp.com\",443\r"); if (!waitForResponse("CONNECT OK", 5000)) { Serial.println("Connection failed!"); return; } Serial3.println("AT+CIPSEND\r"); waitForResponse(">", 1000); // Wait for the send prompt // Send properly formatted HTTPS POST request Serial3.println("POST https://test.000webhostapp.com/send.php HTTP/1.1"); delay(250); Serial3.println("Host: test.000webhostapp.com"); delay(250); Serial3.println("Content-Type: application/x-www-form-urlencoded"); delay(250); Serial3.println("Content-Length: 9"); // Correct length for "i=15&p=69" delay(250); Serial3.println(); // Critical blank line to separate headers from body delay(250); Serial3.println("i=15&p=69"); delay(250); Serial3.write(0x1A); // Ctrl Z to end transmission waitForResponse("SEND OK", 5000); Serial3.println("AT+CIPCLOSE"); waitForResponse("CLOSE OK", 2000); Serial3.println("AT+CIPSHUT"); waitForResponse("SHUT OK", 2000); }
Additional Checks
- Double-check your APN setting (
AT+CSTT="internet","","") matches your mobile carrier’s requirements (you said local testing worked, so this is probably fine, but worth confirming) - Log into your 000webhost dashboard and make sure there’s no firewall rule blocking incoming requests from mobile networks
- Verify your
send.phpis still accessible via HTTPS (paste the URL into a browser to confirm)
内容的提问来源于stack exchange,提问作者Tom

