Hi
I’m trying to create code that will read analog value and post it to a webserver.
I have functional code tested with Arduino Yún:
/*
Yún HTTP Client
*/
#include <Bridge.h>
#include <HttpClient.h>
int value = 0;
uint64_t tickCount;
uint64_t tickCountSeconds;
void setup() {
SERIAL_PORT_USBVIRTUAL.begin(9600); // initialize serial communication
if (Serial.availableForWrite()) Serial.println("Waiting...");
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin(); // make contact with the linux processor
digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready
if (Serial.availableForWrite()) Serial.println(F("Setup complete"));
}
uint64_t millis64() {
static uint32_t low32, high32;
uint32_t new_low32 = millis();
if (new_low32 < low32) high32++;
low32 = new_low32;
return (uint64_t) high32 << 32 | low32;
}
void loop() {
tickCount = millis64();
value = analogRead(A0);
if (Serial.availableForWrite()) Serial.println(value);
if (tickCount >= tickCountSeconds) {
tickCountSeconds = tickCount + 1000;
HttpClient client;
//client.get("http://192.168.2.15/iot.php?f=0-test.json&v=" + String(value));
while (client.available()) {
char c = client.read();
if (Serial.availableForWrite()) SerialUSB.print(c);
}
}
SerialUSB.flush();
}
Testing the examples found here Advanced Wi-Fi Usage I constantly end up with a Seeeduino XIAO that has to be put to Bootloader Mode to have the com-port show up in the device manager.
After uploading HTTP GET Example the XIAO shows up in device manager as Unknown USB Device (Device Descriptor Request Failed)
. Also tested the WiFiManager example, with the same result.
This is the furthest I’ve come with XIAO code:
/*
Seeeduino XIAO HTTP Client
*/
uint64_t tickCount;
uint64_t tickCountSeconds;
uint64_t tickCount10thSeconds;
uint64_t millis64() {
static uint32_t low32, high32;
uint32_t new_low32 = millis();
if (new_low32 < low32) high32++;
low32 = new_low32;
return (uint64_t) high32 << 32 | low32;
}
// the setup routine runs once when you press reset:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
}
// the loop routine runs over and over again forever:
void loop() {
tickCount = millis64();
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
if (Serial.availableForWrite()) Serial.println(sensorValue);
if (tickCount >= tickCountSeconds) {
tickCountSeconds = tickCount + 1000;
// post sensorValue to webserver
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
if (tickCount >= tickCount10thSeconds) {
tickCount10thSeconds = tickCount + 10000;
// check WiFi connection
}
delay(1); // delay in between reads for stability
}
How can I mitigate my issues with the WiFi Usage examples?