Esp8266 refuses to connect to wifi

after I upload my code to my esp the serial monitor shows {Connection to "wifi-name" failed
Retrying in "500" milliseconds}
Debug:
0It�I�dM�$<���***** Arduino IoT Cloud - configuration info *****
Device ID: id
Thing ID: id
MQTT Broker: mqtts-up.iot.arduino.cc:8884
WiFi status ESP: 6
Connection to "wifi-name" failed
Retrying in "500" milliseconds
Connection to "wifi-name" failed
etc.

code
pastebin

/* 

Sketch generated by the Arduino IoT Cloud Thing "Untitled" 

https://create.arduino.cc/cloud/things/2413a6ab-2daf-4c8d-a323-7845e5cfcbd2 

 

Arduino IoT Cloud Variables description 

 

The following variables are automatically generated and updated when changes are made to the Thing 

 

int potentiometer; 

 

Variables which are marked as READ/WRITE in the Cloud Thing will also have functions 

which are called when their values are changed from the Dashboard. 

These functions are generated with the Thing and added at the end of this sketch. 

*/ 

 

#include "thingProperties.h" 

 

void setup() { 

pinMode(A0,INPUT); 

// Initialize serial and wait for port to open: 

Serial.begin(9600); 

// This delay gives the chance to wait for a Serial Monitor without blocking if none is found 

delay(1500); 

 

// Defined in thingProperties.h 

initProperties(); 

 

// Connect to Arduino IoT Cloud 

ArduinoCloud.begin(ArduinoIoTPreferredConnection); 

 

/* 

The following function allows you to obtain more information 

related to the state of network and IoT Cloud connection and errors 

the higher number the more granular information you’ll get. 

The default is 0 (only errors). 

Maximum is 4 

*/ 

setDebugMessageLevel(2); 

ArduinoCloud.printDebugInfo(); 

} 

 

void loop() { 

ArduinoCloud.update(); 

 

// Your code here 

potentiometer = analogRead(A0); 

 

} 

 

/* 

Since Potentiometer is READ_WRITE variable, onPotentiometerChange() is 

executed every time a new value is received from IoT Cloud. 

*/ 

void onPotentiometerChange() { 

 

// Add your code here to act upon Potentiometer change 

} 

 

 


Okay so the problem is, that if I try to upload with analogRead() and pinmode, it fails, but without these two lines it works.

Welcome to the forum

Please post your code here to make it easy yo see and copy for examination rather than posting a link to an external site

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the </> icon above the compose window) to make it easier to read and copy for examination

Have you tried running the "wi-fi scanner" example sketch, to check the esp can see the access point you want to connect to?

Post your code in code tags.

I'll try